Which Linux commands must be mastered?

Linux has many commonly used commands, the following are some common commands that must be mastered in daily use:

1. ls: used to list the files and subdirectories in the directory. Common options are:

    • -l: Displays file details in long format.
    • -a: Show all files, including .hidden files starting with .
    • -h: Displays the file size in human readable format.
    • -R: Recursively display subdirectory contents.

2. cd: used to change the current working directory. Example:

    • cd /path/to/directory: Switch to the directory of the specified path.
    • cd ..: Switch to the upper level directory.
    • cd ~: Switch to the current user's home directory.

3. pwd: Display the path of the current working directory.

4. mkdir: Create a new directory. Example:

    • mkdir directory_name: Create directory_namea directory named .

5. rm: used to delete files and directories. Common options are:

    • -r: Recursively delete a directory and its contents.
    • -f: Forcefully delete a file or directory without confirmation.

6. cp: used to copy files and directories. Example:

    • cp file1 file2: will be file1copied to file2.
    • cp -r directory1 directory2: Copy the directory and its contents to directory2.

7. mv: used to move files and directories, or rename files and directories. Example:

    • mv file1 file2: will be file1moved or renamed to file2.
    • mv file1 directory: will file1move to directorydirectory.

8. touch: Create a new file or update the access time and modification time of an existing file. Example:

    • touch file_name: Create file_namean empty file named .
    • touch -a file_name: only updated file_nameaccess time.
    • touch -m file_name: Only file_namethe modified time of the update.

9. cat: used to view the contents of the file. Example:

    • cat file_name: Displayed file_namecontent.

10. less: Display file content page by page, suitable for large files. Example:

    • less file_name: Open file_name, use the up and down arrows to browse the contents.

11. grep: Search for the specified pattern in the file. Example:

    • grep pattern file_name: file_nameSearch in pattern.

12. find: Search files according to the specified conditions. Example:

    • find /path/to/search -name "pattern"pattern: Search for files matching the pattern by name in the specified path .

13. chmod: Modify the permissions of files or directories. Example:

    • chmod permissions file_name: file_nameSet the permissions for permissions to permissions.
    • chmod +x script.sh: Add execution permission to the script file.

14. chown: Modify the owner of a file or directory. Example:

  • chown user_name file_name: file_nameChange the owner of to user_name.
  • chown user_name:group_name file_name: file_nameChange the owner to user_nameand the group to group_name.

15. chgrp: Modify the group to which a file or directory belongs. Example:

  • chgrp group_name file_name: file_nameChange the belonging group to group_name.

16. sudo: Execute commands as a super user (root). Example:

  • sudo command: Execute as superuser command.

17. su: switch user identity. Example:

  • su username: Switch to usernameuser.

18. tar: Create and extract archive files (compressed files). Example:

  • tar -cvf archive.tar file1 file2: Pack file1and file2as archive.tar.
  • tar -xvf archive.tar: Unzip archive.tarthe file.

19. gzip: compress files. Example:

  • gzip file_name: compress file_name, generate file_name.gz.

20. unzip: decompress files. Example:

  • unzip file_name.zip: Unzip file_name.zipthe file.

These commands cover common tasks such as file and directory manipulation, rights management, file searching, and compression. Of course, the Linux system provides more powerful commands and functions, which can be further studied and mastered according to needs.

Dark Horse Programmer's new version of Linux from zero basics to mastering quickly, covering Linux system knowledge, common software environment deployment, Shell scripts, cloud platform practice, big data cluster project combat, etc.

 

Guess you like

Origin blog.csdn.net/Itmastergo/article/details/132555423