Top 20 Linux Commands

1) clear command

clear is a standard operating system command which is used to clear the terminal screen. This command brings the command line on the top of the terminal. By pressing the ‘ctrl+L' shortcut key, you can also clear the terminal screen.

Syntax:  

$ clear

Before using the clear command

top 20 linux command

After using the command, the terminal screen will look like this.

top-20-linux-command-1

 2) exit command

This command is used to close the terminal window or exit the shell. It takes one more parameter which exits the terminal or a shell.

Also, use the shortcut key ‘ctrl+shift+w’ to close the shell or terminal window and ‘ctrl+shift+q’ for close all the terminal tabs.

Syntax:

$ exit [n]
top 20 linux command 2

 3) echo command

The echo command is used to print the line of text or a string or a number. It prints the string that passes as an argument in the command.

Syntax:

 $ echo [option] [string]
top 20 linux command 3

Different options used in an echo command

 (a) ‘/b’: ‘/b’ is a backspace option used with a backslash interpreter

‘-e.’

top 20 linux command 4

(b)  ‘\t’: This option is used in a string for the horizontal tab spaces using the backslash interpreter ‘-e.’

top 20 linux command 5

(c) ‘\n’:  ‘\n’ option is used to break a string or a line of text by using the backslash interpreter ‘-e.’

top 20 linux command 6

 (d) ‘\v’: This option is used for the vertical tab space.

top 20 linux command 7

 (e) ‘\c’: It is also used with the backslash interpreter ‘-e’ and produce no further string after it.

top 20 linux command 8

(f) ‘echo *’: This option ‘*’ displays the files and directories as similar to the ‘ls’ command.

Syntax:

$ echo*
top 20 linux command 9

 4) history command

The history command displays all previously used commands since the session was started.

Syntax:

$ history
top 20 linux command 10

5) pwd command

pwd stands for present working directory which shows the path of the working directory starting from the root.

Syntax:

$ pwd
top 20 linux command 11

6)  cd command

The 'cd' command is used to change the current working directory into its child or parent directory or any other directory (home or root directory).

Syntax:

 $cd [directory_name] 
top 20 linux command 12

Different types of cd commands in Linux

 (a) ‘cd ..’: This command is used to change the current directory to the parent directory.

Syntax:

$ cd ..
top 20 linux command 13

 (b) ‘cd/’: ‘cd/’ is used to move the user to the root directory.

Syntax:

 $ cd/
top 20 linux command 14

(c) ‘cd~’: this command is used to change the current directory to home directory.

Syntax:

 $ cd~
top 20 linux command 15

(d) cd dir1/dir2/dir3

This command is used to change a directory from the parent directory.

top 20 linux command 16

7)  ls Command

The ls command shows the list of all the files and folders in the current working directory.

Syntax:

  $ ls [option] 
top 20 linux command 17

Options used with ls command

 (a) ‘ls --version’: this option shows the version of ls.

Syntax:

$ ls --version
top 20 linux command 18

(b)  ‘ls~’: This option ‘ls~' shows the list of files and directories of the home directory.

Syntax:

 $ ls~
top 20 linux command 19

 (c) ‘-a’: It shows the list of all the files and directories with the hidden files started with the .dot symbol in the current directory.

Syntax:

$ ls -a
top 20 linux command 20

 (d) ‘-d */’: It is used to display only the list of directories.

Syntax:

$ ls -d */
top 20 linux command 21

(e)  ‘-R’: This option of ls command displays the file of subdirectories also.

Syntax:

$ ls -R
top 20 linux command 22

 8) mkdir command

mkdir stands for make directory and it is used to create a new directory in a file system. It takes one or more argument as a directory name. It also creates multiple directories by passing their directory names in the command. By using this command, you can also set permission to the directory.

Syntax1:

 $ mkdir [option] directory_name    

Syntax2:

$ mkdir dir1 dir2 dir3 ... dirN
  • By using the ‘ls' command, you can verify that the directory is successfully created or not.
top 20 linux command 23

Different options used in mkdir command

 (a) ‘--version’:  This option shows the version of mkdir and its brief information about the license.

Syntax:

$ mkdir--version
top 20 linux command 24

(b) ‘-v’: This option of mkdir gives the message for each created directory.

Syntax:

$ mkdir -v directory_name
top 20 linux command 25

 (c) ‘-p’: This option creates the parent directory as necessary.

Syntax:

$ mkdir -p dir1/dir2/..../dirN 
top 20 linux command 26

 (d) ‘--help’: This option shows the help related information.

Syntax:

$ mkdir --help
top 20 linux command 27

 9) rmdir command

It stands for remove directory.

This command is used to remove the existing empty directory from the file system and takes one more argument as a directory name. It removes each directory specified in the rmdir command.

Syntax1:

 $ rmdir [option] directory_name   

Syntax2:

  $ rmdir dir1 dir2 dir3 ... dirN  

Different options used in rmdir command

 (a) ‘--version’: This option displays the version of rmdir.

Syntax:

$ rmdir–version
top 20 linux command 28

(b) ‘-v’: This option of mkdir gives the message for each deleted directory.

Syntax:

$ rmdir -v directory_name
top 20 linux command 29

 (c) ‘-p’: This option deletes or removes the child directory then its parent directory from the file system.

Syntax:

$ rmdir-p dir1/dir2/..../dirN 
top 20 linux command 30

 (d) ‘--help’: This option shows the general information or syntax of the command.

Syntax:

$ rmdir --help
top 20 linux command 31

10) cp command

The 'cp' command is used to copy the file or directory from one location (source) to another location (destination). This command takes at least two arguments as a file name. It can also copy more than one file in a single directory.

Syntax:

  $ cp [option] Source Destination 
  • Copy the content of one file into the second file

Syntax:

$ cp first_file_name  second_file_name
top 20 linux command 32
  •  Copy multiple files to a single directory

Syntax:

$ cp source_file1 Source_file2 ... Source_fileN Destination_directory
top 20 linux command 33
  • Copy all the files(not directories) of source Directory to Destination Directory (*)

Syntax:

 $ cp * Destination_directory
top 20 linux command 34

Different options used in the cp command

(a) ‘-i or -interactive’: This option warns you before overwriting the destination file. If you print ‘y,’ destination file is overwritten by the source file.

Syntax:

$ cp -i sourec_file Destination_file
top 20 linux command 35

 (b) ‘-b’: This option creates a backup of each destination file in the same folder or directory with the different name and format.

Syntax:

$ cp --backup source_file destination_file
top 20 linux command 37

(c)  ‘-R’: This option copies all the files of source directory to the destination directory.

Syntax:

$ cp -R source_directory_name path_of_dest_directory
top 20 linux command 37

 (d) ‘-p’: This option preserves the attributes of source file like mode, timestamp, and ownership.

Syntax:

cp -p source_file Destination_file

(e) ‘--help’: This option shows or displays the general syntax or information about the cp command.

Syntax:

 $ cp --help
top 20 linux command 40

11) mv command

‘mv’ stands for move and is used to move one and more files and directories from one place to another directory or location in a Linux file system.

This command is also used to rename a file, folder, and directory by passing the old name of a file and new name as an argument.

  • To move directory

Syntax:

 $ mv [option] source_directory destination_directory 
top 20 linux command 41
  •  Move Multiple files in a single directory

Syntax:

$ mv file1 file2 .... fileN destination_directory_name
  • To rename a file or directory

Syntax:

$ mv old_name new_name
top 20 linux command 43

 12) touch command

The touch command is a standard command used in Linux for creating the empty files if not exits. It is also used to create, change and modify the timestamp (i.e., date and time) of the file. It takes at least one argument as a file name.

Syntax:

$ touch file_name
top 20 linux command 44
  • Create multiple files

By using the touch command, you can also create multiple files by passing their names in the command.

Syntax:

$ touch file1 file2 file3 .... fileN
top 20 linux command 45

Different options used in touch command

Like all the other commands touch command also has the various option which are as follows:

(a) ‘ --version’: This option shows the version of touch and information regarding the license.

Syntax:

$ touch --version
top 20 linux command 46

 (b) ‘-a’: This option is used to change the access time of a file.

Syntax:

$ touch -a file_name
top 20 linux command 47

(c)  ‘-m’: This option changes the modification time of the file.

Syntax:

$ touch -m file_name
top 20 linux command 48

 (d) ‘-r’: This option will update the timestamp (access and modify time) of file2 according to the timestamp of file1.

Syntax:

$ touch -r file1 file2
top 20 linux command 49

 (e) ‘-t’: This option is used to create a file with specifies time rather than the current time.

Syntax:

$ touch -t YYMMDDHHMM.SS file_name
top 20 linux command 50

13) cat command

cat (concatenate) command reads the data from the file and displays the content of the file as an output on the terminal. It also helps to append the content of a text file to the end of another text file.

  • Display the content of a file

You can display the content of a file by passing the file name as an argument in a command line.

Syntax:

  $ cat [option] file_name 
top 20 linux command 51
  • Display the content of multiple files

You can also display the content of multiple files by passing their names as an argument in the cat command.

Syntax:

$ cat file1 file2 file3 ...... fileN
top 20 linux command 52
  • Copy the content of one file into another file

Syntax:

$ cat source_file > destination_file
top 20 linux command 53
  • Append the content of one file to the end of another file

Syntax:

$ cat source_file >> destination_file
top 20 linux command 54
  • Display the content in reverse order

You can display the content of a file in reverse order by using the tac command.

Syntax:

$ tac file_name
top 20 linux command 55

Different options used in cat commands

(a) ‘-n’: This option shows the line number with each line in a file.

Syntax:

 $ cat -n file_name
top 20 linux command 56

 (b) ‘-E’: This option displays the ‘$’ sign at the end of the line.

Syntax:

$ cat -E file_name
top 20 linux command 57

 (c) ‘-T’: This option displays the character (^I) for tab space if it is present in any line of a file.

Syntax:

$cat -T file_name
top 20 linux command 59

14) ln command

ln command is used to link two files and directories in Linux.

There are two types of link:

Hard link:  Hard links create links between two or more filenames with the same inode number. By default, the ln command creates a hard link between files. It links directly to data on disk or the physical data.

Soft Link: It is also known as symbolic link or symlink. Symbolic link or soft link does not directly link to the data on disk they relate to another link.

  • Create a hard link

Syntax:

 $ ln file1 link1 

If you delete a file ‘f1.txt', you can access the content of the file by ‘f2.txt' in the hard link as shown in the below figure:

top 20 linux command 61

Create a soft link/ symbolic link:

You can create a symbolic link or soft link by using the ‘-s.'

Syntax:

 $ ln -s path_of_file_name  link_name 
top 20 linux command 62

If you delete the file ‘s1.txt', you cannot access the content of s1.txt by using the s2.txt in the symbolic link, as shown in the below figure, but it is possible in hard link:

top 20 linux command 63

15) date command

The ‘date’ command is used to display the current date and time of the system. A super-user can change the value of the system date and time.

Syntax:

$ date [option] [Format]

When you run date command without any option, then it will display the output as shown in below screen:

top 20 linux command 64

16) ps command

‘ps’ stands for ‘processes status,’ and this command is used to display the currently running processes with their process Identification number, i.e., PIDs along with some other information for each process depends on the different options.   

Syntax:

$ ps [option]

If you execute the ps command without any option, it shows the processes for the current shell as shown in below screen.

top 20 linux command 65

Different options used in ps command

(a) ‘-A or -e’: This option prints all the processes running in your Linux system.

Syntax:

$ ps -A
top 20 linux command 66

(b) ‘au or axu’: This option displays all the process running in the BSD format.

Syntax:

$ ps au
top 20 linux command 67

 (c) ‘ -U root -u root’: This option displays all the processes running as a root user (real and valid ID).

Syntax:

$ ps -U root -u root
top 20 linux command 68

 (d) ‘ -e –forest’: This option displays the process tree (A process tree that shows how the processes linked to each other in a Linux system).

Syntax:

$ ps -e --forest
top 20 linux command 69
top 20 linux command 70

17) whoami command

whoami is mainly the concatenation of the string “who” ,”am”,”i” and when this command is executed, then it displays the username of the current user.

Syntax:

$whoami [option]
top 20 linux command 71

Different options used in the whoami command

(a)  ‘--version’: This option displays the information about the version of whaomi.

Syntax:

$ whoami --version
top 20 linux command 72

(b) ‘--help’: This option gives the general syntax about whaomi command and its options.

Syntax:

$ whoami –help
top 20 linux command 73

18) passwd command

The passwd command changes the password of a user account in Linux. When you are changing the password, make sure that you are using a unique and strong password.

To change the password, run the following passwd command without any option:

Syntax:

$passwd
top 20 linux command 74
  • ‘--help’:  This option show information about how to use the passwd command.

Syntax:

$passwd --help
top 20 linux command 75

19) uname command

The uname command shows the information about the system, such as machine name, Operating system, and kernel.

Syntax:

$ uname [option]
top 20 linux command 76

Different options used in the uname command

(a) ‘-a’: This option displays the system information in an order as shown in below screen.

Syntax:

$ uname -a
top 20 linux command 77

 (b) ‘-s’: This option displays the kernel name.

Syntax:

$ uname-s
top 20 linux command 78

(c) ‘-n’: This option displays the hostname of the network node.

Syntax:

$ uname-n
top 20 linux command 79

 (d) ‘-v’: This option displays the current kernel’s version.

Syntax:

$ uname -v
top 20 linux command 80

 (e) ‘-p’: This option prints the type of the processor.

Syntax:

$ uname-p
top 20 linux command 81

20) apt command

The Debian based ‘apt’ command stands for Advanced Package Tool. Apt is a package manager for Debian based systems like Ubuntu, Kubuntu, Lubuntu, etc., that automatically and intelligently search, update, install, and resolves dependency of packages on Linux system from command line Interface.

Syntax:

$apt-get package_name 
top 20 linux command 82