All Linux directory commands and manipulate files

All Linux directory commands and manipulate files

All Linux directory commands and manipulate files
All Linux directory commands and manipulate files 

Linux Directory Commands

1. pwd Command

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

Syntax:

  1. pwd

Output:

Linux Commands with Examples

2. mkdir Command

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

Syntax:

  1. mkdir <directory name>

Output:

Linux Commands with Examples

3. rmdir Command

The rmdir command is used to delete a directory.

Syntax:

  1. rmdir <directory name>

Output:

AD

Linux Commands with Examples

4. ls Command

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

Syntax:

  1. ls

Output:

Linux Commands with Examples

5. cd Command

AD

The cd command is used to change the current directory.

Syntax:

  1. cd <directory name>

Output:

Linux Commands with Examples

Linux File commands

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> ....

Output:

Linux Commands with Examples

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>

Output:

Linux Commands with Examples

8. rm Command

The rm command is used to remove a file.

Syntax:

rm <file name>

Output:

Linux Commands with Examples

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:

Output:

Linux Commands with Examples

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>

Output:

Linux Commands with Examples

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

Output:

Linux Commands with Examples

Linux File Content Commands

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>

Output:

Linux Commands with Examples

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>

Output:

Linux Commands with Examples

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>

Output:

Linux Commands with Examples

15. more command

The more command is quite similar to the cat command, as it is used to display the file content in the same way that the cat command does. The only difference between both commands is that, in case of larger files, the more command displays screenful output at a time.

In more command, the following keys are used to scroll the page:

ENTER key: To scroll down page by line.

Space bar: To move to the next page.

b key: To move to the previous page.

/ key: To search the string.

Syntax:

  1. more <file name>

ess Command

The less command is similar to the more command. It also includes some extra features such as 'adjustment in width and height of the terminal.' Comparatively, the more command cuts the output in the width of the terminal.

Syntax:

  1. less <file name>

Output:

Linux Commands with Examples

Linux User Commands

17. 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:

Linux Commands with Examples

18. id Command

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

Syntax:

  1. id

Output:

Linux Commands with Examples

19. useradd Command

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

Syntax:

  1. useradd  username

Output:

Linux Commands with Examples

20. passwd Command

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

Syntax:

  1. passwd <username>

Output:

Linux Commands with Examples

21. groupadd Command

The groupadd command is used to create a user group.

Syntax:

  1. groupadd <group name>

Output:

Linux Commands with Examples

Linux Filter Commands

22. cat Command

The cat command is also used as a filter. To filter a file, it is used inside pipes.

Syntax:

  1. cat <fileName> | cat or tac | cat or tac |. . .

Output:

Linux Commands with Examples

23. cut Command

The cut command is used to select a specific column of a file. The '-d' option is used as a delimiter, and it can be a space (' '), a slash (/), a hyphen (-), or anything else. And, the '-f' option is used to specify a column number.

Syntax:

  1. cut -d(delimiter) -f(columnNumber) <fileName>

Output:

Linux Commands with Examples

24. 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:

Linux Commands with Examples

25. 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>

Output:

Linux Commands with Examples

26. sed command

The sed command is also known as stream editor. It is used to edit files using a regular expression. It does not permanently edit files; instead, the edited content remains only on display. It does not affect the actual file.

Syntax:

  1. command | sed 's/<oldWord>/<newWord>/'

Output:

Linux Commands with Examples

27. tee command

The tee command is quite similar to the cat command. The only difference between both filters is that it puts standard input on standard output and also write them into a file.

Syntax:

  1. cat <fileName> | tee <newFile> |  cat or tac |.....

Output:

Linux Commands with Examples

28. tr Command

The tr command is used to translate the file content like from lower case to upper case.

Syntax:

  1. command | tr <'old'> <'new'>

Output:

Linux Commands with Examples

29. uniq Command

The uniq command is used to form a sorted list in which every word will occur only once.

Syntax:

  1. command <fileName> | uniq

Output:

Linux Commands with Examples

30. wc Command

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

Syntax:

  1. wc <file name>

Output:

Linux Commands with Examples

31. od Command

The od command is used to display the content of a file in different s, such as hexadecimal, octal, and ASCII characters.

Syntax:

  1. od -b <fileName>      // Octal format
  2. od -t x1 <fileName>   // Hexa decimal format
  3. od -c <fileName>     // ASCII character format

Check other links

The fastest ways to increase your PC performance
After 18 years of experience, we’ve discovered how to increase your PC performance with easy to follow methods that keep your computer clean and running smoothly. Read these top 10 tips from our certified technicians that you can use to improve your computer’s speed and overall performance today!

or

Top best commands in Linux, most useful with instruction
Top best commands in Linux, most useful with instruction