Linux common commands--file operation, permission setting

1. Edit the file

vi aaa.txt Open aaa.txt file    
The esc key toggles between edit and command modes    
In the command mode, enter: (colon), you can enter the command    
:s /string1/ string2 Replace string1 with string2    
:wq ! Do file save and exit    
:q ! Force quit file editing    

2. View the content of the file

cat aaa.txt View the content of the aaa.txt file    
    
head - 5 aaa.txt View the first 5 lines of the aaa.txt file    
    
tail - 10 aaa.txt displays the last 10 lines of the aaa.txt file   

 

3. Operating users and user groups

 
su root switch to root user    
whoami View currently logged in users    
groups View the group to which the current user belongs    
id View current user UID and GID    
useradd adds a new user (under root)    
passwd sa Set the password of the sa user (under root)    
passwd change password    
userdel delete user (under root)    
 
groupadd g1 Add g1 group (under root)    
usermod -g g1 sa assign the sa user to the g1 group (under root)

 

4. Set file permissions

 
chmod 751 temp sets 751 permissions to the temp folder    
 -rwxr-x-- x    
 111  101  001     
751 
all indicate a permission,
-rwxr-x-- x , 111 101 001, 751 cannot type the expression of authority, the authority level is the same, the above 751 can be replaced with the other two appearances. 
ps is used to display the status of the current process. 

Permission explanation:

-r-xr-xr--
101 101 100 binary
554
-rw--w---x
110 010 001
621
-rwxrwxr--
111 111 100
774
-r---w---x
100 010 001
421

Summary rule: r means 4, w means 2, x means 1


 

 

Guess you like

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