Saturday, 8 July 2023

Essential Linux commands for beginners

Hello Friends!! Good Morning 😊

If you are working in Linux environment or managing the Linux server, you can't live without theses commands. So, in today's blog, I will discuss about some essentials Linux commands which are frequently used in Linux arena.


Let's come with me 😉

1. Print Working Directory[pwd]

When you type pwd in your Linux terminal and as soon as press the enter button, it will display your current working directory location. So, anyone want to know in which directory currently he/she is working, please use this command.

Syntax: pwd [OPTION]

There are two options available to display the locations-
-L, --logical : To display your location with any symbolic.
-P, --physical: To display your location after resolving any symbolic.

Example:
[brajesh@linux log]# pwd -L
/home/brajesh/logs
[brajesh@linux logs]# pwd -P
/var/logs

2. ls -Listing command

Well! guys, if you want to see the whole content of any directory you can you simply ls command. The main aim of this command is to see all files available in the directory.

Syantx: ls [option]

ls Option Description
ls -a In Linux, hidden files start with . (dot) symbol and they are not visible in the
regular directory. The (ls -a) command will enlist the whole list of the current directory including the hidden files.
ls -l It will show the long list.
ls -lh This command will show you the file sizes in human readable format.
Size of the file is very difficult to read when displayed in terms of byte.
The (ls -lh)command will give you the data in terms of Mb, Gb, Tb, etc.
ls --version It will check the version of ls command.
ls -li Will print the index number, if file is present in the first column.
ls -p It is used to identify the directory easily by marking the directories with a slash (/) line sign.
ls -r It is used to print the list in reverse order.
ls -R It will display the content of the sub-directories also.
ls -lt It will sort the list by displaying recently modified filed at top.
ls ~ It gives the contents of home directory.
ls ../ It give the contents of parent directory.
ls -n It is used to print group ID and owner ID instead of their names.
ls -d */ It is used to display only subdirectories.
ls --color=[VALUE] This command is used to print list as colored or discolored.

3. cd -Change directory

This changes the current directory. Note that it uses a forward slash. The example used here changes the location to a Linux directory that is present in all versions of Linux.

When you use ls –I you will be able to see more details of the contents in the directory. It lists the following:
  • Permissions associated with the file
  • The owner of the file
  • The group associated with the file
  • The size of the file
  • The timestamp
  • The name of the file
Example:
$ cd /var/log

4. grep -For searching the text.

This finds text in a file. The grep command searches through many files at a time to find a piece of text you are looking for.

Syntax: grep pattern [FILE_NAME]

Suppose you want to search 'error' in tomcat.log file, which is available under var/log. Then your grep command will go like this-
$ grep 'error' /var/log/tomcat.log

5. passwd-Change the password.

Though it looks similar to the pwd command, this command is very different. This command is used to change the user account password.

You could change your password or the password of other users. Note that the normal system users may only change their own password, while root may modify the password for any account.

Syntax: passwd [username]- changes the password for the user.

$ passwd admin 

6.  mv- Rename or move the file.

The mv command moves a file or renames it. Here the file name gets changed from first.txt to second.txt.
$ mv first.txt second.txt 
If you want to verify your changes, please to ls to see.

7.  cp- Copy command

This command copies a file. The cp command issues a copy of the file second.txt in the same directory.
$ cp first.txt second.txt 
You can use ls – lto see the new file created.

8.  rm- Remove file or directory

This command is used to remove files in a directory or the directory itself. A directory cannot be removed if it is not empty.

Syntax:
rm [name of the file]
rm –r removes all the contents in a directory and the directory as well.

$ rm file1.txt
$ rm -r myDirectory

9.  mkdir- Make a directory

The mkdir command makes a directory. The command is written as follows:
 
Syntax: mkdir [directory name]
$ mkdir myDirectory

10.  chmod- Make a directory

This command changes the mode of a file system object. Files can have read, write, and execute permissions.

Example:
  • chmod mode FILE
  • chmod 744 script.sh
  • The first number stands for the user who is associated with the file
  • The second number is for the group associated with the file
  • The third number is associated with everyone else who is not a part of the user or group
$ chmod 744 myDirectory

11.  chown- Change the owner

This command is used to change the ownership of a file/folder or even multiple files/folders for a specified user/group.

Syntax: chown [owner_name] [file_name]
$ chown admin1 file.txt
Assume that if you are a user named user1and you want to change ownership to rootuse “sudo”.
$ sudo chown root file.txt

12.  cat- Concatenate files 

The cat command (short for “concatenate”) is one of the most frequently used commands in Linux. cat command allows you to create single or multiple files, view contents of files, concatenate files (combining files), and redirect output in terminal or files.
$ cat file.txt
$ cat file1.txt file2.txt
The output will be the entire contents of the file(s).

13.  wc- Word count

The wc(word count) command is used to find out the number of new lines, word count, byte, and characters count in a file specified by the file arguments.

Syntax: wc [options] filenames
$ wc -l readme.txt
Shows the output as - 150 readme.txt
  • wc -l : Prints the number of lines in a file.
  • wc -w: Prints the number of words in a file.
  • wc -c : Displays the count of bytes in a file.
  • wc -m: Prints the count of characters from a file.
  • wc -L: Prints only the length of the longest line in a file.

14.  history- To show history

This command is used to show previously used commands or obtain information about the commands executed by a user.
$ history

15.  clear- To clear terminal

This command clears the terminal screen.
$ clear

16.  reboot- To reboot your system

This command halts, powers off, or reboots a system.
$ reboot

17.  diff- To compare two files

The diff command compares two files line by line to find differences. The output will be the lines that are different.
$ diff file1.txt file2.txt

18.  exit- To exit

The exit command exits the current shell. When you hit enter, you’ll be taken out of the terminal.
$ exit

19.  kill- To kill process

The kill command is used to end a process, usually an unresponsive one. The kill command also includes the process ID or the program name, as shown here:
$ kill 566789

20.  useradd- To add a new user

The useradd command creates a new user. The username is added after the useradd command, as follows:
$ useradd brajesh

Conclusion

We hope this Linux commands list will help you get started. These are just a few commands — there are many more that you’ll find yourself using over time, but this is a good starting point. The best way to learn Linux is by trying these commands yourself and also by taking course. Below we list the best Linux courses you can take today! 

Thank you !!! 😊








Related Posts:

  • How to install Google Chrome For installing Google Chrome in your Ubuntu system, you have need to follow some following steps. STEP 1 : Execute the following commands- cd /tmp wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.d… Read More
  • How To Install MySQL on Ubuntu 16.04 MySQL is an open-source database management system, commonly installed as part of the popular LAMP(Linux, Apache, MySQL, PHP/Python/Perl) stack. It uses a relational database and SQL (Structured Query Language) to manage its… Read More
  • How To Install VirtualBox 5.2 on Linux Mint 19 / Linux Mint 18 VirtualBox is an open-source hypervisor application that helps you create and run guest operating systems (“virtual machines”) such as Linux and Windows under a host operating system. VirtualBox can be installed on hos… Read More
  • How to fix sudo after “chmod -R 777 /usr/bin”? Today, by mistakenly, I set the 'sudo chmod -R 777' to my /usr/bin folder as a root user. After doing that, I found that , my sudo command was not working at all. After spending a couple (of) hours over googl… Read More
  • How To Install java 8 On Ubuntu 16.04 / 17.10 / 18.04 Today, from this post , I will try to show you, how we can install java 8 in   Ubuntu 16.04 / 17.10 / 18.04 environment. So lets start... For doing this you need to follow some steps these are as below:- Step 1: A… Read More

0 comments:

Post a Comment