To view
The command | explain |
---|---|
ls | View the files in the directory |
ls -a | View directory files (including hidden files) |
ls -R a | View all levels in the directory |
ls -L a | View details in directory A |
pwd | View the current directory |
cat | Text content is displayed to the terminal |
head -5 a | View the first 5 lines of file A, default 10 lines |
tail -3 a | Look at the end of file A 3 lines, default 10 lines |
tail -f a | Look at the A file, and do update tracking |
wc -l a | See how many lines are in file A |
whoami | View your user name |
Create a directory
The command | explain |
---|---|
mkdir a | Create a directory named A |
mkdir a b c | Create directories A, B, and C |
mkdir -p a/b/c | Create a multi-level directory. In this example, directory C under directory B is created |
delete
The command | explain |
---|---|
rmdir a | If you want to delete directory A, only an empty directory can be deleted |
rm -rf a | Delete a directory, non-empty directory can also be deleted, and no prompt, use with caution! |
copy
The command | explain |
---|---|
cp -r css-magic a/ | Copy the entire csS-maigc directory to directory A |
cp -r dir* .. / | Copy all directories starting with dir to the directory at the previous level |
cp -r dir? ../ | Copy directories starting with dir + one character to the directory at the previous level |
cp -p | Retain file attributes such as user, permission, and time |
cp -a | Equivalent – dpR??? |
mobile
The command | explain |
---|---|
mv a b | Move or rename file A to b |
Packaging and compression
The command | explain |
---|---|
tar cf a.tar a | Package a file |
ls -lh a.tar | View the size of a compressed file in units, for example, M/G |
tar czf a.tar.gz a | Package and compress the a file, where.tar.gz is a double extension to indicate that the file is compressed for readability, CZF c for package, Z for zip, and f for file operation type |
tar cjf a.tar.bzip2 a | Bzip2 compression is higher than Gzip but slower than Bzip2 compression |
tar xzf a.tar.gz -C ./ | Decompress the S package to the current directory. In XZF, x stands for unzip, z because the unzip is gzip, and f is a file |
Text editing
The command | explain |
---|---|
vi a | Go inside file A |
- operation
Text editing operation instructions | explain |
---|---|
hjkl | Cursor position movement |
yy | Copy the entire line |
3yy | Copy 3 rows consecutively |
y$ | Copy from cursor position to end |
p | paste |
d | shear |
5dd | Represents a continuous cut of 5 lines |
u | Undo last operation, can be undone many times |
ctrl + r | Too many retractions. Pull back |
x | Delete the specified character |
R + New character | replace |
:set nu | According to the line Numbers |
:set nonu | Remove the line Numbers |
/x | To find the character x, press N (down), Shift + N (up) to move it up or down |
:s/m/o | Replace the m character with o on the line where the cursor is located |
:%s/m/o/g | All m characters found in the text are replaced with O |
:set hlsearch | Display search highlighting |
:set nohlsearch | Remove search highlighting |
v | Visual mode (single character) |
shift + v | Visual mode (row) |
ctrl + v | Visual mode (block) |
Users and user groups
The command | explain |
---|---|
Enter the password after sudo -i | Temporarily switch to root to perform root permissions |
su – a | Switch to user A |
exit | Switch back to a common user from the root user |
useradd a | Create a user named A |
id a | Query for user A |
passwd a | Change user A’s password |
userdel -r a | Delete user A, if -r is not added, then the user’s home directory is not deleted |
usermod | Modifying User Information |
The output
The command | explain |
---|---|
echo | Displays information on the terminal |
echo 123 > a.log | Print 123 to the a.log file |
other
The command | explain |
---|---|
cd | Change the directory |
touch | Create a file |
File directory
The path | explain |
---|---|
/etc/passwd | Store user files |
/etc/shadow | User password related files |
chmod | Example Modify file and directory permissions |
chmod u+x readme.md | Add execute permission to the user part of the readme.md file. U = user, + = add permission, x = execute permission (r: read, w: write, x: execute) |
chmod g-r readme.md | G-r: g stands for group, – stands for delete, r stands for read (r reads, W writes, x executes) |
chmod o=w readme.md | Add write permission to other user permissions of the readme.md file. O =w indicates other, = indicates one-time operations, such as deleting read permission and adding write permission. W indicates write permission (r read, W write, x execute). |
chmod a+r readme.md | Add read permission to all users, groups, and other users of the readme.md file. In a+ R, a stands for all, + stands for add, and r stands for read permission (r reads, W writes, and x executes). |
chmod 111 readme.md | Configure only execute permissions for readme.md file users and other users. 111: the first 1 represents user, the second 1 represents group, and the third 1 represents other users (1 performs 2 writes 4 reads). |
chmod 777 readme.md | Configure all permissions for the readme.md file user and other user groups. 7 represents 1+2+4 (1 performs 2 writes 4 reads). |
chown | Change the owner and owner group |
chown a test | Change the owner of the test file to user A. Chown is short for change owner and requires root permission |
/ / vim/etc/passwd file clsmall: x: 1001-1001: : / home/clsmall: / bin/shCopy the code
explain
- Clsmall: user name
- X: Whether password authentication is required
- The first 1001: UID, which cannot be changed arbitrarily, will be programmed for that user if it is changed to an existing ID
- Second 1001: Which group does the current user belong to
- /home/clsmall: indicates the location of the home directory
- /bin/sh: indicates the user command interpreter
- There are two consecutive colons in it
: :
This is the position of the comment
// vim /etc/shadow clsmall:$6$jveUn92k1qeyIivH$YnBK/M8w6Tpj0.M0a4hRVX6GPjeN//4Klp2Qmbs5pV4Zv/nkVhhQUDBS00h5Gv7DUHe1w2laywUoASlFC0Lwj.:18795 : 0:9 9999:7: : :Copy the code
explain
- Clsmall: indicates the user name
- After a string: encrypted password, here even if the same password is set, encryption is not the same, in order to avoid the set out of the password
// vim /etc/group
root:x:0:
Copy the code
explain
- Root: indicates the group name
- X: Whether password authentication is required
- 0: Gid is 0
Log is used as an example. -rwxrwxrwx 1 cl cl 44 Jun 11 15:35 publishCopy the code
explain
-
Represents a common file- RWXRWXRWX: r stands for read, w stands for write, and x stands for execute. The first RWX represents the permissions of the file owner, the second RWX represents the permissions of the file owner group, and the third RWX represents the permissions of other users.
Drwxr-xr-x 1 cl cl 4.0K Jun 21 18:25 test drwxr-xr-x 1 cl cl 4.0K Jun 21 18:25 testCopy the code
explain
- D: indicates a directory file. The owner has read and write permissions on the test directory, and the owner group and other users have read and execute permissions on the test directory
Special privileges
// /usr/bin/passwd The // s file indicates that the owner permission is obtained when the command is executed. Root -rwsr-xr-x 1 root root 67K May 28 2020 passwd //usr/bin/temp // t indicates that only root and the user who created the file can operate the file DRWXRWXRWT 1 root root 512 Jun 22 10:47 tmpCopy the code