0% found this document useful (0 votes)
45 views

Linux Commands List With Examples

The document describes 31 Linux commands including their syntax and usage. Some commands are used to navigate and manipulate files and directories like pwd, ls, cd, mkdir. Other commands are used to view and edit file contents like cat, head, tail. Additional commands help manage users, permissions, and system resources.

Uploaded by

hitesh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Linux Commands List With Examples

The document describes 31 Linux commands including their syntax and usage. Some commands are used to navigate and manipulate files and directories like pwd, ls, cd, mkdir. Other commands are used to view and edit file contents like cat, head, tail. Additional commands help manage users, permissions, and system resources.

Uploaded by

hitesh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Linux Commands

1. pwd Command

The pwd command is used to display the location of the current working directory.

Syntax:

1. pwd

2. mkdir Command

The mkdir command is used to create a new directory under any directory.

Syntax:

1. mkdir <directory name>

3. rmdir Command

The rmdir command is used to delete a directory.

Syntax:

1. rmdir <directory name>

4. ls Command

The ls command is used to display a list of content of a directory.

Syntax:

1. ls

5. cd Command

The cd command is used to change the current directory.

Syntax:
1. cd <directory name>

6. touch Command

The touch command is used to create empty files. We can create multiple empty files
by executing it once.

Syntax:

1. touch <file name>


2. touch <file1> <file2> ....

7. cat Command

The cat command is a multi-purpose utility in the Linux system. It can be used to
create a file, display content of the file, copy the content of one file to another file,
and more.

Syntax:

1. cat [OPTION]... [FILE]..

To create a file, execute it as follows:

1. cat > <file name>


2. // Enter file content

Press "CTRL+ D" keys to save the file. To display the content of the file, execute it as
follows:

1. cat <file name>

8. rm Command

The rm command is used to remove a file.

Syntax:

rm <file name>

9. cp Command

The cp command is used to copy a file or directory.


Syntax:

To copy in the same directory:

1. cp <existing file name> <new file name>

To copy in a different directory:

10. mv Command

The mv command is used to move a file or a directory form one location to another
location.

Syntax:

1. mv <file name> <directory path>

11. rename Command

The rename command is used to rename files. It is useful for renaming a large group
of files.

Syntax:

1. rename 's/old-name/new-name/' files

For example, to convert all the text files into pdf files, execute the below command:

1. rename 's/\.txt$/\.pdf/' *.txt

12. head Command

The head command is used to display the content of a file. It displays the first 10
lines of a file.

Syntax:

1. head <file name>


13. tail Command

The tail command is similar to the head command. The difference between both
commands is that it displays the last ten lines of the file content. It is useful for
reading the error message.

Syntax:

1. tail <file name>

14. tac Command

The tac command is the reverse of cat command, as its name specified. It displays
the file content in reverse order (from the last line).

Syntax:

1. tac <file name>

15. su Command

The su command provides administrative access to another user. In other words, it


allows access of the Linux shell to another user.

Syntax:

1. su <user name>

Output:

16. id Command

The id command is used to display the user ID (UID) and group ID (GID).

Syntax:

1. id

17. useradd Command

The useradd command is used to add or remove a user on a Linux server.

Syntax:
1. useradd username

18. passwd Command

The passwd command is used to create and change the password for a user.

Syntax:

1. passwd <username>

19. groupadd Command

The groupadd command is used to create a user group.

Syntax:

1. groupadd <group name>

20. grep Command

The grep is the most powerful and used filter in a Linux system. The 'grep' stands for
"global regular expression print." It is useful for searching the content from a file.
Generally, it is used with the pipe.

Syntax:

1. command | grep <searchWord>

Output:

Cat marks.txt | grep 9

21. comm Command

The 'comm' command is used to compare two files or streams. By default, it displays
three columns, first displays non-matching items of the first file, second indicates the
non-matching item of the second file, and the third column displays the matching
items of both files.

Syntax:
1. comm <file1> <file2>

22. wc Command

The wc command is used to count the lines, words, and characters in a file.

Syntax:

1. wc <file name>

23. sort Command

The sort command is used to sort files in alphabetical order.

Syntax:

1. sort <file name>

24. gzip Command

The gzip command is used to truncate the file size. It is a compressing tool. It
replaces the original file by the compressed file having '.gz' extension.

Syntax:

1. gzip <file1> <file2> <file3>...

25. gunzip Command

The gunzip command is used to decompress a file. It is a reverse operation of gzip


command.

Syntax:

1. gunzip <file1> <file2> <file3>. .

26. cal Command

The cal command is used to display the current month's calendar with the current
date highlighted.
Syntax:

27. sleep Command

The sleep command is used to hold the terminal by the specified amount of time. By
default, it takes time in seconds.

Syntax:

1. sleep <time>

28. time Command

The time command is used to display the time to execute a command.

Syntax:

1. time

29. df Command

The df command is used to display the disk space used in the file system. It displays
the output as in the number of used blocks, available blocks, and the mounted
directory.

Syntax:

1. df

Output:

30. clear Command

Linux clear command is used to clear the terminal screen.

Syntax:

1. clear

31. ping Command


The ping command is used to check the connectivity between two nodes, that is
whether the server is connected. It is a short form of "Packet Internet Groper."

Syntax:

1. ping <destination>

You might also like