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:  

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:

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:

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:

top 20 linux command 9

 4) history command

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

Syntax:

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:

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:

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:

top 20 linux command 13

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

Syntax:

top 20 linux command 14

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

Syntax:

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:

top 20 linux command 17

Options used with ls command

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

Syntax:

top 20 linux command 18

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

Syntax:

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:

top 20 linux command 20

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

Syntax:

top 20 linux command 21

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

Syntax:

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:

Syntax2:

  • 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:

top 20 linux command 24

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

Syntax:

top 20 linux command 25

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

Syntax:

top 20 linux command 26

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

Syntax:

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:

Syntax2:

Different options used in rmdir command

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

Syntax:

top 20 linux command 28

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

Syntax:

top 20 linux command 29

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

Syntax:

top 20 linux command 30

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

Syntax:

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:

  • Copy the content of one file into the second file

Syntax:

top 20 linux command 32
  •  Copy multiple files to a single directory

Syntax:

top 20 linux command 33
  • Copy all the files(not directories) of source Directory to Destination Directory (*)

Syntax:

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:

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:

top 20 linux command 37

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

Syntax:

top 20 linux command 37

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

Syntax:

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

Syntax:

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:

top 20 linux command 41
  •  Move Multiple files in a single directory

Syntax:

  • To rename a file or directory

Syntax:

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:

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:

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:

top 20 linux command 46

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

Syntax:

top 20 linux command 47

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

Syntax:

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:

top 20 linux command 49

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

Syntax:

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:

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:

top 20 linux command 52
  • Copy the content of one file into another file

Syntax:

top 20 linux command 53
  • Append the content of one file to the end of another file

Syntax:

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:

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:

top 20 linux command 56

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

Syntax:

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:

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:

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:

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:

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:

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:

top 20 linux command 66

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

Syntax:

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:

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:

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:

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:

top 20 linux command 72

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

Syntax:

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:

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

Syntax:

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:

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:

top 20 linux command 77

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

Syntax:

top 20 linux command 78

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

Syntax:

top 20 linux command 79

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

Syntax:

top 20 linux command 80

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

Syntax:

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:

top 20 linux command 82