Table of contents
1. Introduction to common Linux commands
1. Basic commands
1.pwd
Display the absolute path of the current location, examples are as follows:
2.cd
To switch directories, the parameter added after cd is the destination, which can be a relative path or an absolute path;
- The abc here is a folder located on the desktop.
- old is a folder in abc.
Relative path:
Absolute path:
-
cd ’ -' Return to the last directory location
-
cd ’~'Directly return to the user's home directory
-
cd’…'Go back to the previous level
-
cd’.'nothing happened
3.ls
Display all files in the directory, examples are as follows:
-
-a show hidden files
-
-l Display detailed information of all files in a list
4.man
View the help manual to view detailed information on specific commands, system calls, and library functions. Examples are as follows:
5.touch
Create an ordinary file, the example is as follows:
before creation:
after creation:
6.mkdir
Create a directory file (folder), the example is as follows: it
will also be added on the desktop:
7.rm
Delete files or folders, note:When deleting a folder, you need to add the parameter "-r", the example is as follows:
Delete ordinary files:
delete folders are divided into, delete empty directories in folders and delete non-empty directories in folders;
delete empty directories:
delete non-empty directories:
8.cp
Copy the file, note: When copying directory files, you need to add the parameter "-r", the example is as follows:
copy of ordinary files:
copy of directory files:
Note: cp -r dir2 dir1 appears twice here:
1. The first execution: dir1 does not exist, and dir1 is successfully created at this time;
2. The second execution: dir1 already exists, and the system treats dir1 as a path.
9.mv (cut, move, rename)
1. Cutting movement, examples are as follows:
2. The example of renaming is as follows:
renaming has the risk of overwriting, use mv carefully.
10.find
Traversing through the directory, you can also specify the starting position of the traversal, examples are as follows:
11. grep filter
- c only shows the number of lines
- v Negate, print all the data other than the search itself
12. pipe '|'
Use the output information of the previous command as the input information of the next command, the example is as follows:
13.wc
Statistical file information, such as (-w) shows how many words (-l) counts the number of lines (-c) Examples are as follows:
14.su
Switch user su+username, if no user name is added, the root user will be switched by default.
The example is as follows:
sudo su switch root user:
exit Exit:
15. Shutdown and restart
- shutdown -h now shutdown immediately
- shutdown -r now restart immediately
- init 0 shutdown
- init 6 reboot
- shut down
- reboot reboot
init level: 0~6 7 levels:
- 0 shutdown
- 1 single user mode
- 2 multi-user without network mode
- 3 Full multi-user text interface
- 4 undefined or custom
- 5 Graphical interface
- reboot
For example, init 3 is a text interface, which is the interface we use most in our work.
16. Modify user password
passwd stu modify
sudo passwd stu force modification
2. Packing, unpacking, compression, and decompression commands
1. tar packs or unpacks files
- c create package file
- f specifies that the target is a file rather than a device
- v show detailed process
- t display the contents of the package without releasing
- x releases the contents of the package
- Z GNU version is newly added, allowing tar to have compression and decompression functions
1.1tar packaging process
1.2tar unpacking process
2.gzip compresses and decompresses files
2.1gzip compresses the file
2.2gzip decompresses the compressed package
- d unzip