Detailed explanation of Linux command format and common directory operation commands

Organized based on the video: Shang Silicon Valley Linux System Management Tutorial (Linux System Management Essentials)
The article is archived at: https://www.yuque.com/u27599042/gny4fg


Linux command format

Linux command prompt

[root@localhost ~]#
  • [ ]: This is the separator symbol for prompts. It has no special meaning and only serves as a separator.
  • root: Displays the current login user. The root user is currently used to log in.
  • @: Delimiter symbol, has no special meaning and only serves to separate.
  • localhost: The abbreviated host name of the Linux system you are currently logged in to (the full host name is localhost.localdomain).
    • Use hostnameto view the full hostname of the current system
    • image.png
  • ~: Represents the directory where the user is currently located. The last directory of the current directory is displayed by default. In this example, the directory where the user is currently located is the home directory.
  • #: Command prompt. Super user is #, ordinary user is $

Basic format of Linux commands

  • All commands in Linux basically follow the following command format:
[root@localhost ~]# 命令 [选项] [参数]
  • Among them, [ ]the content enclosed by means that it is optional
  • Options: are used to adjust the functionality of the command.
  • Parameter: It is the operation object used to specify the command. If the parameter is omitted, it is because there are default parameters.

Detailed explanation of common directory operation commands in Linux

ls

  • Command name: ls.
  • Original English meaning: list.
  • Location: /bin/ls.
  • Execute permissions: all users.
  • Function description: Display the contents of the directory.
  • Options:
    • -a: Display all files and directories in the directory
    • –color=when: Support color output, set whether to display color when displaying files in the directory. The default value of when is always (always display color), or it can be never (never display color) and auto (automatic)
    • -d: Display the specified directory information instead of the files in the specified directory
    • -h: Humanized display, display file size according to the units we are accustomed to
    • -i: Display the i node number of the file
    • -l: Long format display, that is, display detailed information of the file. If this option is not provided, only the file name will be displayed by default.
  • Parameters: The directory where the content is to be displayed, the default is the current directory

-a

  • Display all files and directories in the directory specified by the parameter, including hidden files. By default, hidden files are not displayed.
    • Hiding a file is not to prevent the user from seeing the file, but to tell the user that the file is important
    • Hidden files, which .start with
  • image.png

–color=when

  • Set whether to display colors when displaying files in the directory. The default value of when is always (always display colors), or it can be never (never display colors) and auto (automatic)
  • image.png

-l

  • Long format display, that is, the detailed information of the file is displayed. If this option is not provided, only the file name will be displayed by default.
  • image.png
  • -lThe seven columns of file details displayed using the option are described as follows:
    • First column: permissions.
    • Second column: reference count. The reference count of a file represents the number of hard links to the file, while the reference count of a directory represents how many first-level subdirectories the directory has.
    • The third column: Owner, that is, which user this file belongs to. The default owner is the user who created the file
    • The fourth column: the group it belongs to. The default group is the effective group of the user who created the file. Generally, it is the group of the user who created the file.
    • Column 5: Size. The default unit is Byte.
    • The sixth column: file modification time. The file status modification time or file data modification time will change this time. Note that this time is not the creation time of the file.
    • Column 7: File name.

-d

  • Display the specified directory information instead of the files in the specified directory
  • By default, if -dthe option is not used, file information in the specified directory will be displayed.
    • If you need to specify multiple options at the same time, -l -dyou can write it directly as-ld
    • If there is no certain order requirement between the command options, then it -ldis -dlequivalent to
  • image.png

-h

  • Humanized display, display file size according to the units we are accustomed to, such as KB, MB, etc.
    • The h here is human
  • image.png

-i

  • Display the inode number of a file
  • image.png

cd

  • Command name: cd.
  • Original English meaning: change directory.
  • Where: Shell built-in commands.
  • Execute permissions: all users.
  • Function description: switch directory.
  • When using this command to switch directories, you need to pay attention to whether you are using a relative path or an absolute path.
    • Relative path: relative to the current directory, the path does not /start with
    • Absolute path: Relative to the root path, the path /starts with
  • Simplified usage of the cd command:
    • ~: Represents the home directory of the currently logged in user
    • -: Represents the last directory
    • .: represents the current directory
    • ..: Represents the superior directory of the current directory

~

  • ~: Represents the home directory of the currently logged in user
  • cd ~You can directly return to the user's home directory by using , cdor you can directly return to the user's home directory by using
  • image.png

-

  • -: Represents the last directory
  • image.png

.

  • .: represents the current directory
  • image.png

  • ..: Represents the superior directory of the current directory
  • image.png

pwd

  • Command name: pwd
  • Original English meaning: print name of current/working directory
  • Location:/bin/pwd
  • Execute permissions: all users.
  • Function description: Query the current working directory.
  • image.png

mkdir

  • Command name: mkdir.
  • Original English meaning: make directories.
  • Location: /bin/mkdir.
  • Execute permissions: all users.
  • Function description: Create an empty directory under the current working directory
  • Options:
    • -p: Recursively create the required directories. By default, Linux only allows the creation of one-level new empty directories.
  • image.png

is rm

  • Command name: rmdir.
  • Original English meaning: remove empty directories.
  • Location: /bin/rmdir.
  • Execute permissions: all users.
  • Function description: Delete the specified empty directory.
  • Options:
    • -p: delete directories recursively
  • The rmdir command can only delete empty directories, so once there is content in the directory, an error will be reported, so it is generally not used. In the future, whether we delete files or directories, we will use the rm command.
  • image.png

Guess you like

Origin blog.csdn.net/m0_53022813/article/details/132458132