Linux-Detailed explanation of common commands (command classification, command help and command explanation)


Preface

  • Linux commands are commands for managing Linux systems. For the Linux system, whether it is a central processing unit, memory, disk drive, keyboard, mouse, or user, it is a file (everything is a file), and the commands for Linux system management are the core of its normal operation.
  • There are two types of linux commands in the system: built-in Shell commands and Linux commands

One, Linux command basis

1.Shell overview

  • A special program running in Linux system
  • Acting as a "translator" between the user and the kernel
  • When the user logs in to the Linux system, a Shell program is automatically loaded
  • Bash is the shell program used by default in the Linux system

Insert picture description here

2. Classification of Linux commands

2.1 The difference between internal commands and external commands

Insert picture description here

2.2 The format of the Linux command line

General command line format: command word [option] [parameter]

(Note: Linux commands (including file names, etc.) are case sensitive, that is to say, if you enter a command with incorrect capitalization, the system will not respond as you expect, so English Case is distinguished; and the format may sometimes change in order, but it has no effect)

2.2.1 Command word

  • Is the most critical part of the entire command
  • The only thing that is certain is that a command
    executes operations, such as new, delete, rename, etc.

2.2.2 Options

  • Short format options: use the "-" symbol to guide (multiple single-character options can be combined together)
  • Long format option: use "–" symbol to guide

2.2.3 Parameters

  • Command word processing object
  • It can be a file name, directory (path) name, or user name, etc.
  • The number can be zero or more

3. Edit the Linux command line

3.1 Auxiliary operations for editing the Linux command line

  • Tab key: automatic completion (display related commands and files)
  • Backslash \" forced line break (used for commands with more parameters, easy to organize and view; Note: Tab may not be possible)
  • Ctrl+U: Clear to the beginning of the line
  • Ctrl+K: Empty to the end of the line
  • Ctrl+L: Clear screen
  • Ctrl+C: Cancel this command edit
  • Ctrl+A: switch to the beginning of the line
  • Ctrl+E: switch to the end of the line

3.2 Command line prompt characters

[root@localhost~]#

  • root: the user currently logged in to the system
  • @: Separator
  • localhost: host name
  • ~: The current directory
  • #: means login as an administrator ($: means login as an ordinary user)

Two, Linux command help

1 Overview

  • #helpProvide help for internal commands
  • #man or info provide help for external commands

If your English is good enough, you can be proficient in Linux without relying on anyone. As long as you can use man,
Man is actually a help for viewing instructions. The most important thing to learn any UNIX operating system is to learn to use man. Auxiliary command

Man is an abbreviation of manual. Its description is very detailed, but because it is all in English, it looks very headache. I
suggest you look at man again when you need it. Normally, just remember some basic usage.

2. How to get command help

To use without internet, of course, it is more convenient to use "Baidu" directly.

2.1 Internal command help

View the help information of Shell internal commands

2.2 Command "–help" option

Suitable for most Linux external commands

2.3 Use man command to read man pages

  • Use the man command to read the man page
  • Use the "↑" and "↓" (ENTER) arrow keys to scroll a line of text·
  • Use Page Up and Page Down (Space) keys to turn pages
  • Press Q or q to exit the reading environment
  • Press "/" key to search for content, n key to search down, N key to search up

3. Basic operations of directories and files

1. View the current working directory-pwd

Insert picture description here

2. Switch working directory -cd

Usually use the target location (folder path) that needs to be switched to as the parameter.
If the target parameter is not specified, the default will switch to the current user's home directory (home directory)

The home directory is the default working directory for Linux users after logging in to the system

Insert picture description here

When representing the location of a certain directory (or file) in the Linux operating system, two different forms can be used according to the starting directory it refers to, which are called absolute path and relative path

2.1 Absolute path

  • Specify the exact location of the file in the entire file system, there will be no ambiguity, starting from the root directory "/" of the file system
  • Because there is only one root directory in the Linux operating system, no matter which directory it is from, using an absolute path can very accurately indicate the location of a directory (or file).
    However, if the path is long, the input will be more cumbersome

2.2 Relative path

Given by the context of the call (current location), the "/" symbol is not used at the beginning,
so it is easier and more convenient to use

Relative paths mainly include the following forms:
Insert picture description here

2.3 Summary

  • Relatively speaking, the use of a relative path to indicate a directory (file) path is flexible and changeable, usually used to identify the location of a directory (file) "near" to the current directory
  • The absolute path is often used to indicate a relatively stable (not frequently changed) directory in the Linux operating system.
  • When choosing a relative path or an absolute path, you should choose according to the actual situation

3. List the contents of the directory -ls

Mainly used to display the contents of the directory, including the relevant attribute information of subdirectories and files, etc.

3.1 Common options

  • -l: Display the detailed information of the file (directory)
  • -a: View hidden files (directories)
  • -A: View hidden files, except for the current directory "." and parent directory ". ."
  • -d: display the attributes of the directory itself, instead of displaying the contents of the directory
  • -h: more user-friendly display of file (directory) size unit information
  • -R: Recursive display (if there are subdirectories, the files in the subdirectories will be displayed in turn)
  • -Color: distinguish file types by color

Black (data file),
white (general file),
blue (directory/file),
red (compressed package),
green (executable file/command file/script),
light blue (link file/shortcut),
yellow (device file/disk) file)

3.2 Combining wildcards

  • "?": Represents any one character, and at least one
  • "*": Represents any number of characters, it can be 0 or 1 or more
  • "[]": means that it can match any character in the character group
    [abc], [af]

4. Set alias-alias

  • Simplify commonly used and longer commands through the alias mechanism
    alias command alias='command' (no spaces on both sides of "=")
  • Example
    Setting myls as the alias of ls -alh
    alias myls='ls -alh'
    can define a command alias named myls, and executing "myls" later will be equivalent to executing the "ls-alh" command
  • Cancel alias
    unalias command aliases

5. Statistic directory and file space occupation-du

  • Count the size of the disk space occupied by the specified directory (or file)

    du [Option] [File or directory....]
  • Commonly used options
    -a: include all files when counting disk space usage, not just the directory
    -h: display the statistical results in a more humane way (the default is in KB, but the unit is not displayed)
    -s: only statistics The total size of the occupied space, instead of counting the size of each subdirectory and file (options -a and -s cannot be used at the same time)
    –max-depth=n: count the total size of all directories less than or equal to the nth level
  • Count the size of the subdirectories in the /var/log directory
    du -h --max-depth=1 /var/log/

6. Create a new directory-mkdir

  • Create a new empty directory
    mkdir [Options] Directory location and name...
    Common options
    -p: create nested multi-level directories at once

  • Example
    ●Create a subdirectory
    mkdir public_html named public_html in the current directory
    
●Create a directory /aa, create a subdirectory bb under the /aa directory, and create a subdirectory cc
    
cC mkdir -p /aa/bb under the /aa/bb directory /cc

7. Create an empty file-touch

  • Time stamp of update file
  • It is often used to create multiple new empty files
    touch files...
  • Example
    Create two empty files, the file names are aa.txt and bb.txt
    touch aa bb
    touch{a,b}.txt

8. Create a link file -ln

Insert picture description here
Soft link is equivalent to express delivery.
Hard link is equivalent to giving a file an individual name.
Insert picture description here
When a file has multiple hard links, modifying the content of the file will affect all file names,
but deleting one file name will not affect other file names. Access
Deleting a file name will only decrease the "number of hard links" by 1. It

should be noted that hard links to directories

are hardly established in daily work.

9. Copy files or directories -cp

  • Rebuild a copy of the file or directory (source) that needs to be copied, and save it as a new file or directory
    
cp [Options]...source file or directory...target file or directory...

  • Commonly used options
    -f: Do not remind when overwriting the target file or directory with the same name, but directly force the copy
    -i: Remind the user to confirm when overwriting the target file or directory with the same name
    -p: Keep the permission, owner and time stamp of the source file when copying Attribute unchanged
    -r: This option must be used when copying directories, which means that all files and subdirectories are recursively copied

Note: When copying multiple files or directories, the target location must be a directory, and the target directory must already exist

10. Delete files or directories -rm (use with caution!)

  • Delete the specified file or directory
    rm [Option] The file or directory to be deleted...
  • Commonly used options
    -f: do not remind when deleting files or directories, but directly force deletion
    -i: remind users to confirm when deleting files or directories (y means delete, n means not delete)
    -r: this option must be used when deleting directories, Means to delete the entire directory tree recursively (should be used with caution)

Note: Do not directly delete the existing directories or configuration files in the system to avoid unexpected failures. When
deleting files in the directory, it is recommended to switch to the directory first and then execute the rm -rf command

11. Move files or directories -mv

  • Move the specified file or directory to the location
  • If the target location is the same as the source location, it is equivalent to performing a rename operation
    mv [Options]… source file or directory… target file or directory
  • Example
    mv mytouch mkfile
    mv mkfile public_html
  • The mv command can only rename a single file, you can use the rename command to modify the file name in batches,
    rename the old character and the new character target file.
    Example: rename jpg gif*.jpg

12. Find the directory where the command file is stored-which

Insert picture description here

13. Find a file or directory-find

Insert picture description here

13.1 Common search condition types

Insert picture description here

13.2 Use the find command to achieve multiple search conditions

  • Use logical operator
    "-a" between expressions to indicate and (and)
    "-o" to indicate or (or)
  • Example
    find /boot -size +1024k-a -name "vmlinuz*"
    both need to meet the conditions
    find /boot -size+1024k-o -name "vmlinuz*"

    meets one of the conditions

13.3 exec usage of find

  • The -exec parameter is followed by the Linux command, which uses a semicolon ";" as the end symbol. Since the semicolon has different meanings in various systems, the backslash escape character "\" is added before the semicolon
    {} represents the file name found by the previous find
  • The find command matches all ordinary files in the current directory, and uses the ls -I command in the -exec option to list them
    find ./ -type f-exec ls -I{}\;

Guess you like

Origin blog.csdn.net/weixin_51486343/article/details/109720264
Recommended