Summary of Linux Basic Commands-Continuous Update


Summary of basic Linux commands



Insert picture description here





1. Linux commands for managing files and directories

Click the title below, it will automatically jump to the detailed explanation of the command ~

1. pwd command
2, cd command
3, ls command
4, cat command
5, grep command
6, touch command
7, cp command
8, mv command
9, rm command
10, vi command
11, dd command





1. Linux commands for managing files and directories

1. The pwd command

#Note: The pwd command will output the full path of the current working directory
Main usage:

(1) The pwd command will output the full path of the current working directory;

        Command: pwd

Insert picture description here

(2) When the pwd command links the directory, pwd -P displays the actual path instead of using the "link" path

        Command: pwd -P

Insert picture description here



2. The cd command

#Note: The cd command changes the directory
Main usage:

(1) Change the directory;

        Command: cd /dirname/

        dirname: the target directory to be switched

        cd dirname

        pwd

Insert picture description here

(2) Return to the last directory;

        Command: cd-

Insert picture description here

(3) Enter the user's home directory (also called home directory);

        Command: cd ~

(4) Return to the superior directory;

        Command: cd…

(5) Return to the upper two-level directory;

        Command: cd …/…

(6) Enter the root directory;

        Command: cd /

(7) Current directory;

        Command: cd.

(8) Use the parameters of the previous command as cd parameters;

        Command: cd !$

Insert picture description here



3. The ls command

#Note: The ls command is to view files or directories (ls command is equivalent to ll command)
The main usage, commonly used options are as follows:

        -a List all files in the directory, including hidden files

        -l List the details in the directory, including permissions, owner, group, size, creation date, whether the file is a link, etc.

        -f Listed files show file types

        -r reverse, list the contents of the directory from back to front

        -R recursive, this option recursively enumerate the contents of all subdirectories in the current directory

        -s size, sort by file size

        -h displays the size of the file in a human-readable way, such as K, M, G as the unit


4. cat command

#Note: The cat command is mainly used to view file contents, create files, merge files, append file contents and other functions
Main usage:

(1) View the 1.txt file;

        Command: cat 1.txt

(2) View the content of the 1.txt file, and number all output lines starting from 1;

        Command: cat -n 1.txt

(3) View the content of the 1.txt file, the usage is similar to -n, except that blank lines are not numbered;

        Command: cat -b 1.txt

(4) Colleagues display the contents of 1.txthe 2.txt files, and note that the file names are separated by spaces instead of commas;

        命令:cat 1.txt 2.txt

(5) Add a line number to each line in the 1.txt file and write it into the 2.txt file, which will overwrite the original content. If the file does not exist, it will be created automatically;

        命令:cat -n 1.txt > 2.txt

        #No -n option means no line number

(6) Add a line number to each line in the 1.txt file and append it to 2.txt. The original content will not be overwritten, and the file will be created automatically if it does not exist;

        命令:cat -n 1.txt >> 2.txt

        # Same as above, without the -n option means not adding the line number

(7) The usage of creating files and writing the contents of files;

        Command: cd /dirname/

        #Note that when creating a file, you must set the end-of-file mark, that is, <<EOF. You can replace EOF with other characters. Note that it is case-sensitive. After the file content is written, you must enter the end-of-file mark EOF. This is a command Will end correctly, indicating that the file is created and the content is written

Insert picture description here
Insert picture description here

5. grep command

#Use: Search for patterns in files
#Description: Linux system is a powerful text search tool. The command is used to search for the pattern specified by the Pattern parameter, and write each matching line to the standard output. These patterns are regular expressions with a limit. They use ed or egrep command style, grep command uses a compressed uncertain algorithm, and its use authority is all users
Main usage:

(1) Print the number of matching lines;

        Option: -c

(2) Regard each specified pattern as an extended regular expression (ERE), the null value of ERE will match all rows;

        Option: -E

(3) It is forbidden to append the name containing this line after the matching line. When multiple files are specified, the file name will be forbidden;

        Option: -h

Insert picture description here

(4) Ignore case when using grep;

        Option: -i

Insert picture description here

(5) Place the relevant line number in the file before each line. The starting line number of each file is 1. When each file is processed, the line counter will be reset;

        Option: -n

(6) Reverse search and output rows that do not match the conditions;

        Option: -v

Insert picture description here

(7) Perform word search;

        Option: -w

(8) Display lines that exactly match the specified pattern without other characters;

        Option: -x

(9) Output the line after the matched keyword (including the matched keyword);

        Option: -A1

(10) Output the previous line of the matched keyword (including the line of the matched keyword);

        Option: -B1

(11) Output one row before and after the matched keyword (including the row of the matched keyword);

        Option: -C1

(12) Realize the logical or relationship between multiple options;

        Option: -e

Insert picture description here

(13) #Basic regular expression metacharacters; for example: grep metacharacters file or directory

        . Match any single character

        \ Ignore the original meaning of special characters in regular expressions

        [] Match any single character in the specified range

        [-] Range, such as [AZ] that means A, B, C to Z all meet the requirements

        [^] Match any single character outside the specified range. #Displaying white is not a match.

        # Matches

(14) Used after the character to specify the number of times, used to specify the number of times the preceding character should appear

        #Example: grep "r{1,3}oot" /etc/passwd

        * Match the preceding character any number of times, including zero times

        .* Any character of any length

        ? Match the preceding character 0 or 1 times

        + Match the character before it at least once

        {n} match the preceding character n times

        {m,n} Match the preceding character at least m times and at most n times

        {,n} match the preceding character up to n times

        {n,} Match the preceding character at least n times

(15) Example: match the root of the /etc/passwd file, where o is 0 or 1 time

Insert picture description here

        #Regular expression (options need to add double quotation marks), position anchor, position where it appears

        ^ Anchor at the beginning of the line, used for the leftmost side of the pattern

        $ Row anchor, used for the rightmost side of the pattern

        ^$ is used to filter blank lines

        ^# User filters lines starting with #

        <or \b prefix anchor, used on the left side of word pattern

        >Or \b Anchor at the end, used on the right side of the word pattern

        <ABC> matches the entire ABC word


6, touch command


7, cp command


8, mv command


9, rm command


10, vi instruction


11. dd command

Guess you like

Origin blog.csdn.net/weixin_44793172/article/details/107254241