Summary of basic Linux commands
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
(2) When the pwd command links the directory, pwd -P displays the actual path instead of using the "link" path
Command: pwd -P
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
(2) Return to the last directory;
Command: cd-
(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 !$
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