[Linux Practical Operation] - Summary of Linux Common Commands + Practical Screenshots

1. Specify the run level command

1. Run level description

0: Shutdown
1: Single-user mode (retrieve root password)
2: Multi-user mode, no network service
3: Multi-user mode, with network service
4: The system is not used, reserved for users
5: Graphical interface
6: System restart

Linux runlevel diagram
insert image description here

2. Switch to the command that specifies the run level

Basic syntax: init[0123456]
Case 1: Switch between different run levels through init, such as 5—>3 and then shut down
init 5
init 3
init 0
Case 2: Retrieve root password
CentOS operation process: enter single-user mode, Then change the root password, because the root password is not required to enter single-user mode.
Power on -> enter the Enter key at boot time > see an interface enter e → see a new interface, select the second line (edit the kernel), enter e - > enter 1 at the end of this line, and then enter the Enter key >Enter b again to enter single-user mode. At this point, we enter single-user mode and use the passwd command to change the root password.
ubuntu enters single user mode: ubuntu enters single user mode .

2. Help command

Function: When we are not familiar with a certain command, we can use the help command provided by Linux to understand how to use this command

1.man command to get help information

Basic syntax: man [command or related configuration information]
Case: View the help information of the ls command
insert image description here
Press q to exit help
insert image description here

2. help command

Function: Get help information for shell built-in commands

Syntax: help command
Case: View the help information of the cd command
insert image description here

3. File directory instructions

1. pwd instruction

Function: Display the absolute path of the current work
insert image description here

2.ls command

Function: View all content information of the current directory

Basic syntax: ls [options] [directory or file]
Common options:
-a: Display all files and directories in the current directory, including hidden ones.
-l : Display all information in a list.
insert image description here

3. cd command

Function: switch to the specified directory

cd [parameters]
Common parameters: absolute path and relative path
cd~ or cd: go back to your home directory
cd... go back to the previous directory of the current directory
Case 1: Use the absolute path to switch to the root directory
cd /root
Case 2: Use a relative path to the /root directory (requires which directory the user is currently in, assuming /usr/lib)
cd …/…/root

4.mkdir command

Function: used to create a directory

Basic syntax: mkdir [options] the directory to create
Common options: -p create a multi-level directory
Case 1: create a directory /home/dog
Case 2: create a multi-level directory /home/animal/tiger

5.rmdir command

Function: delete empty directory

Basic syntax: rmdir [options] Empty directory to delete
Case 1: Delete a directory /home/dog
Precautions
What rmdir deletes is an empty directory. If there is content in the directory, it cannot be deleted.
If you need to delete a non-empty directory, you need to use rm -rf the directory to delete

6.touch command

Function: Create empty file

Basic syntax: touch filename
Case 1: Create an empty file hello.txt

7. cp command

Function: Copy files to the specified directory

Basic syntax: cp [options] source dest
Common options: -r Copy the entire folder recursively
Case 1: Copy /home/aaa.txt to the /home/bbb directory
Case 2: Copy the entire folder recursively, copy /home/ Copy the entire directory of test to the /home/zwj directory
insert image description here

8.rm command

Function: Remove [Delete] file or directory

Basic syntax: rm [options] The file or directory to delete
Common options:
-r: delete the entire folder recursively
-f: force delete without prompting
Case 1: put /home/aaa.txt /home/psdz/data/server/ default.conf delete
insert image description here

Case 2:
insert image description here

9.mv command

Function: Move files and directories or rename
Basic syntax: mv oldNameFile newNameFile (rename)
mv /temp/movefile/targetFolder (move file)
Case 1: Rename /home/aaa.txt file to pig.txt
Case 2: Move the /home/pig.txt file to the /root directory

10. cat instruction

Function: View the contents of the file and open it as read-only

Basic syntax: cat [options] The file to be viewed
Common options: -n display the line number
Application example
Case 1: /etc/profile View the content of the file and display the line number
cat can only browse the file, but cannot modify the file, for the convenience of browsing , usually with a pipeline command|more
cat file name|more [page browsing]

11.more command

Function: A text filter based on VI editor, which displays the content of the text page by page in a full-screen manner. The more command has built-in shortcut keys.

Basic syntax: more file to be viewed
Case: use more to view the file /etc/profile
built-in shortcut keys:

operate Function Description
blank key (space) page down
Enter scroll down one line
q The representative leaves more immediately and no longer displays the content of the file
Ctrl+F scroll down one screen
Ctrl+B Return to previous screen
= print the line number of the current line
:f Output file name and line number of the current line

12.less command

Function: The less command is used to view the file content in split screen. Its function is similar to the more command, but it is more powerful than the more command and supports various display terminals. The less command displays the file content transaction, not after loading the entire file at one time, but loading the content according to the display needs, which is more efficient for displaying large files.

Basic syntax: less file to be viewed
Case: use less to view a large file /opt/Jin Yong-The Legend of the Condor Heroes txt fine comparison version.txt

13. > Directives and >> Directives

Function: > command is output redirection: overwrite the original file content
>> command is append: will not overwrite the content of the original file, but append to the end of the file.

Basic syntax:
(1) ls -l > file (write the contents of the list to the file a.txt, and create the file if it does not exist)
(2) ls -al >> file (append the contents of the list to the file aa.txt)
(3) cat file 1 > file 2 (overwrite the content of file 1 to file 2)
(4) echo "content" >> file

14. echo command

Function: output content to the console

Basic syntax: echo [options] [output content]
Case: Use the echo command to output environment variables and output the current environment path.
echo $PATH

15.head directive

Function: It is used to display the content of the beginning of the file. By default, the head command displays the content of the first 10 lines of the file.

Basic syntax: head file (view the first 10 lines of the file)
head -n 5 file (view the first 5 lines of the file)
Case: view the first 5 lines of code in /etc/profile (head -n 5 /etc/profile)

16.tail command

Function: It is used to output the tail content of the file. By default, the tail command displays the last 10 lines of the file.

Basic syntax:
(1) tail file
(2) tail -n 5 file
(3) tail -f file (track all updates of the document in real time, often used in work)

17.ln command

Function: Soft links are also called symbolic links, similar to shortcuts in Windows, which mainly store the path to link other files

Basic syntax: ln -s [original file or directory] [soft link name] (create a soft link for the original text)
Case 1: Create a soft link linkToRoot in the /home directory and connect to the /root directory
ln -s /root linkToRoot
Case 2: Delete the soft link linkToRoot

18.history directive

View historical commands that have been executed, and you can also execute historical commands

Basic syntax: history
case 1: display all historical commands
Case 2: display the 10 most recently used commands
Case 3: execute the command whose history number is 5

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324124441&siteId=291194637