One 、 Command format
Linux The basic format of the command in is as follows ：
command [ Options ] [ Parameters ]
notes ： Some special commands do not follow this format
Two 、 system information
2.1、 Get the current user
who am i
2.2、 Get the current directory
2.3、 obtain IP Information
2.4、 Connect to remote address
ping domain name |IP
3、 ... and 、 Directory command
3.1、 List the contents
ls [-aldtr] [ Directory name ] # By default, the directory name lists the current directory # -a： List all the files and directories # -l： List file and directory details # -d： List only the directory itself # -t： Sort by creation time # -r： In reverse order
ll [-aldtr] [ Directory name ] # ls -l Abbreviated form , And ls Use consistent
3.2、 Toggle directory
cd [ route ] # When the directory name is missing , Switch to the current user's home Under the table of contents
Special directory path ：
|~||Current user's home Catalog|
|-||Return to the last Directory|
3.3、 Create directory
mkdir [-mp] Directory name # -m： Specify permissions # -p： Create multi-level directory
3.4、 Delete directory
rmdir Directory name # Only empty directories can be deleted rm [-rf] Resource name # Delete resources ( Directory or file ) # -r： Recursive delete # -f： Don't ask
3.5、 Copy resources
cp [-rp] Source resource path Target resource path # -r： Recursive replication # -p： Copy with attributes , Instead of using default properties
3.6、 Move / Rename resource
mv The source of resources [ The target path ][ New resource name ] # If the target path is not written , That is to rename ; If the new resource name is not written , Mobile ; If you write both , Move and rename
Four 、 File command
4.1、 create a file
touch file name [ file name ] [ file name ] [ file name ]...
4.2、 Edit the file
vi | vim file name # Enter view mode i | a | o # Enter edit mode # i： Start editing at the current cursor ;a： After the current cursor ;o： Start a new line under the cursor ; ESC # Launch editing mode : # Enter the bottom line command mode wq! # Save and exit q! # Exit without saving # In view mode , Press down ZZ( Twice capitalized z), Save and exit quickly
4.2.1、 Show / Hide line numbers
In bottom line command mode , Input
set nu/nonu enter , You can show or hide line numbers
4.2.2、 Jump to a line
In bottom line command mode , Input
to n enter , Can jump to n That's ok
4.2.3、 Find content
In view mode , Input
/xxx You can find... In the file xxx Content , Press
n Find the next one ; Press
N Find the last one
5、 see file
5.1、 Check all
cat file name # Start with the first line to see the contents of the file , Show it all tac file name # View the contents of the file from the last line , Show it all nl file name # Start with the first line to see the contents of the file , Show it all , And display the line number
5.2、 View by page
similar cat , But it will be displayed page by page , More convenient for users to read page by page , And the most basic command is to press the blank key （space） The next page shows , Press b The key will go back （back） One page shows
more file name
Common operation command
- Enter Down n That's ok , Need to define . The default is 1 That's ok
- Ctrl+f Scroll down one screen
- Space bar Scroll down one screen
- Ctrl+b Scroll up one screen
- b Scroll up one screen
- = Output the line number of the current line
- ：f Output filename and line number of current line
- v call vi Editor
- ! command call Shell, And execute the command
- q sign out more
And more similar ,less You can browse files at will , Support page turning and search , Supports page up and page down .
less file name
Common operation command
- / character string ： Search down " character string " The function of
- ? character string ： Search up " character string " The function of
- n： Repeat the previous search （ And / or ? of ）
- N： Repeat the previous search in reverse （ And / or ? of ）
- b Page up
- d Turn back half a page
- h Show help screen
- q sign out less command
- u Scroll forward half a page
- y Roll a line forward
- Space bar Scroll one page
- Enter key Roll a line
- G Jump to the last line
- [pagedown]： Page down
- [pageup]： Page up
5.3、 View by line
head Command can be used to view the contents of the beginning of a file , There is a common parameter -n Used to display the number of rows , The default is 10, It shows 10 The content of the line .
head [-qvcn] file name # -q： Hide filename ( Default ) # -v： Show filename # -c： How many characters are displayed # -n： How many lines are displayed
tail The command can be used to view the contents of a file , There is a common parameter -f Often used to look up log files that are changing .
tail -f filename Will be able to filename The last part of the file is shown on the screen , And keep refreshing , as long as filename Update to see the latest file content .
tail [-fqvcn] file name # -f： Cyclic reading , Read out every time new content is added # -q： Do not display processing information # -v： Display processing information # -c < number >： Number of characters read # -n < number >： Number of rows read
5、 ... and 、 Pack command
Linux The commonly used compression package format in is ：.tar、 .tar.gz、.gz Of , But it also supports .zip and .rar Format .
tar [-cvzf] Compressed file name Target resource name [-C Pathname ] # -c or --create： New compressed file # -v： Display during execution of instructions # -z or --gzip or --ungzip： adopt gzip Instruction processing backup file . # -f < Compressed file name > or --file=< Compressed file name >： Specify the compressed file . Be careful , This option must be at the end of the option
tar [-xvzf] Compressed file name [-C Pathname ] # -x or --extract or --get： Unzip the compressed file
5.1.3、 View compressed files
tar [-tvzf] Compressed file name # -t or --list： List the contents of the compressed file .
Linux This is not supported by default zip, So you need to install zip and unzip Software .
The installation command is as follows ：
yum -y install zip yum -y install unzip
zip [-qr] Compressed file name [ Target resources ] [ Target resources ] ... # -q： Do not show instruction execution # -r： Recursive processing , Process all files and subdirectories in the specified directory
unzip [-lnv] Compressed file name # -l： Display the files contained in the compressed file # -n： When decompressing , Don't override the original file # -v： Look at the contents of the compressed file , Do not decompress
gzip Is a command that can be compressed or decompressed , After it compresses the file , The name will be followed by ".gz" Extension .
gzip [-drl] Resource name | Compressed file name # -d： decompression # -r： Recursive processing # -l： List information about compressed files
6、 ... and 、 User command
Linux The system is a multi-user and multi task time-sharing operating system , Any user who wants to use system resources , You must first apply to the system administrator for an account , Then enter the system as this account .
On the one hand, the user's account can help the system administrator to track the users who use the system , And control their access to system resources ; On the other hand, it can help users organize files , And provide security protection for users .
Each user account has a unique user name and password .
After the user enters the correct user name and password at login , You can access the system and your home directory .
6.1、 Create user
useradd [-dgG] user name # -d： Specify the user's home directory , If not specified , It's in /home Create a folder with the same user name as the home directory # -g： Specifies the user's membership group # -G： Specify the user's satellite group
6.2、 Set the password
passwd [-dlu] user name # -d： Delete password # -l： Lock account , Make it unavailable # -u： Unlock the account , Make it available
6.3、 Switching users
su user name
[root@192 ~]# ：root The user is in 192 Sign in , The current in the ~ Under the table of contents ,# On behalf of Super Administrator .
[silence@192 root]$ ：silence The user is in 192 Sign in , The current in the root Under the table of contents ,$ On behalf of ordinary users .
6.4、 Modify the user
usermod [-degGlLuU] user name # -d < Log in to the directory >： Modify the directory when the user logs in # -e < Term of validity >： Modify the validity period of the account # -f < Buffer days >： Modify how many days after the password expires to close the account # -g < group >： Modify the user's group # -G < group >： Modify the additional group to which the user belongs # -l < Account name >： Change user account name # -L： Lock user password , Invalidate password # -u <uid>： Modify the user ID. # -U： Unlock password .
6.5、 Delete user
userdel [-r] user name # -r： Delete the user's home directory
7、 ... and 、 User group command
Each user has a user group , The system can centrally manage all users in a user group . Different Linux The system has different rules for user groups , Such as Linux The following user belongs to a group of users with the same name , This user group is created at the same time as the user is created .
7.1、 Create user group
groupadd [-g gid] Group name # -g gid： Specified group id
groupadd The command is used to create a new workgroup , Information about the new workgroup will be added to the system file .
Related documents :
- /etc/group Group account information .
- /etc/gshadow Security group account information .
- /etc/login.defs Shadow Password Suite configuration .
7.2、 Modify user groups
groupmod [-n gname] Group name # -n： Modify user group name
7.3、 Delete user group
groupdel Group name
8、 ... and 、 File permissions
Reference resources ：
Linux The system is a typical multi-user system , Different users are in different positions , Have different permissions .
In order to protect the safety of the system ,Linux The system accesses the same file for different users （ Including catalog files ） There are different rules for the authority of .
stay Linux We can use ll perhaps ls –l Command to display the properties of a file and the users and groups to which the file belongs .
stay Linux The first character in represents that the file is a directory 、 Files or linked files, etc .
- When it comes to d It's a directory
- When it comes to - File ;
- if l Is represented as a linked document (link file);
- if b It means the interface equipment available for storage in the device document ( Random access device );
- if c Is the serial port device in the device file , For example, keyboard 、 mouse ( Disposable reading device ).
In the next characters , In groups of three , And they are rwx The combination of three parameters of . among , r Representative readable (read)、 w Representative may write (write)、 x Representative executable (execute). It should be noted that , The location of these three permissions will not change , If you don't have permission , There will be a minus sign - nothing more .
The properties of each file are shown in the first section on the left 10 Characters to determine ：
Use from left to right 0-9 These numbers represent .
The first 0 Bit to determine the file type , The first 1-3 The position is the owner （ The owner of the document ） Have permission to this file . The first 4-6 The genus group is determined by the position （ The same group of users of the owner ） Have permission to this file , The first 7-9 Determine that other users have permissions for this file .
about root Users , In general , The file's permissions don't work for it .
8.1、 Modify file belongs to group
chgrp [-R] Group name file name # -R： Recursive modification
8.2、 Modify file owner
The generic group can be modified at the same time
chown [-R] user name [: Group name ] file name
8.3、 Modify file permissions
chmod [-R] xyz file name
Linux There are two ways to set file properties , One is numbers , One is the symbol .
Linux There are nine basic permissions for a file , Namely owner/group/others( The owner / Group / other ) Each of the three identities has its own read/write/execute jurisdiction .
Let's review the data just mentioned above ： The permission character of the file is ： -rwxrwxrwx , The nine permissions are in groups of three ！ among , We can use numbers to represent each authority , The score comparison table of each authority is as follows ：
Each identity (owner/group/others) Three rights of each (r/w/x) Scores need to be accumulated , For example, when the permission is ： -rwxrwx--- The score is ：
- owner = rwx = 4+2+1 = 7
- group = rwx = 4+2+1 = 7
- others= --- = 0+0+0 = 0
Options and parameters ：
- xyz : This is the permission attribute of the number type just mentioned , by rwx The addition of attribute values .
- -R : Recursion (recursive) Continuous change of , That is to say, all files in the subdirectory will be changed
Nine 、 Process command
9.1、 Check the process
ps -ef | grep Process keywords
View the firewall process ID：
9.2、 Close the process
kill [- Semaphore ] pid # Common semaphores ：1 (HUP)： Reload process .9 (KILL)： Kill a process .15 (TERM)： Normally stop a process .