当前位置:网站首页>Commands and permissions for directories and files
Commands and permissions for directories and files
2022-06-30 07:29:00 【My deep blue】
Catalog 、 File commands and permissions
1 Directory command
- Directory switching
cd
cd / // Switch to the root directory
cd .. // Go back to the previous Directory
cd ~ // Return to your home directory
cd - // Return to the upper level directory
- Catalog view
pwd // View the current directory path
ls // View the directory under the current directory 、 file
ls -l // View the detailed directory under the current directory 、 file
ls -i // View the directory under the current directory 、 Document number
ls -lh // View the directory under the current directory 、 File size
ls -a // Display all files
ls -ld // Look at the catalog itself
- Create directory
mkdir a // establish a Catalog
mkdir -p dir1/dir2/a // If there is no dir Catalog , be -p Automatically create
- duplicate catalog
cp -r dir1 dir2 // Copy dir1 In the same directory , name dir2
cp -r dir1 dir2 dir3 // Copy dir1 dir2 To dir3 Under the table of contents
- Mobile directory
mv dir1 dir2 // If dir2 non-existent , amount to dir1 rename dir2
mv dir1 dir2 dir3 // If dir3 There is ,dir1 and dir2 Move to dir3
- Delete directory
rm -r a // Delete a Catalog
rm -rf a b c // Forced deletion of included files and directories
- System catalog
Directory name | effect |
---|---|
/boot | System boot directory ,Liunx Startup time , Required documents such as : Kernel files and boot loader files |
/dev | Device file , Hardware file |
/etc | The configuration file , Script files |
/home | The root directory where all user files are stored , Is the base point of the user's home directory , Such as user user The home directory of /home/user, It can be used ~user Express |
/root | Administrator home directory |
/proc | Virtual file system saved to memory . Save the kernel of the system , process , External device status and network status lights . Such as /proc/cpuinfo Is save CPU The information of ,/proc/devices yes To save a list of device drivers ,/proc/filesystems Is to save the list of file systems ,/proc/net yes To save network protocol information |
/sys | Virtual file system . and /proc The catalog is similar to , It's all stored in memory , It is mainly stored in kernel related information |
/srv | Service data directory .- - After some system services are started , You can save the required data in this directory |
/tmp | Temporary directory . The directory where the system stores temporary files , All users in this directory can access and write |
/usr | System software resource directory . yes “Unix SoftwreResource” Abbreviation , It is the directory where the system software resources are stored . Most of the software installed in the system is stored here , |
/var | Dynamic data storage location . Mainly save cache 、 Logs and files generated by software operation |
/media | Mount Directory . System recommendations are for mounting media devices , For example, floppy disks and compact disks |
/mnt | Mount Directory , In the early Linux There is only one mount directory in the , There is no subdivision . Now the directory system recommends mounting additional devices , Such as U disc , Partition of mobile hard disk and other operating systems |
/opt | Storage location of software installed by a third party . This directory is where other software is placed and installed , I manually install the source code package software can be installed into this directory . But I'm still more used to putting software in /usr/loca1/ Directory of , in other words /usr/local/ Directories can also be used to install software |
/run | Process documents |
/bin | Directory where system commands are stored , Common users and super users can execute . But put it on /bin’ The command under can also be executed in single user mode |
/ sbin | Save commands related to system environment settings , Only the super user can use these commands to set the system environment , But some commands allow ordinary users to view |
/usr/bin | Directory where system commands are stored , Common users and super users can execute . These commands have nothing to do with system startup , Cannot execute in single user mode |
/usr/sbin | Store unnecessary system management commands for the root file system , For example, most service programs . Only super users can use . You can actually notice Linux The system of , In all “sbin" The commands saved in the directory can only be used by super users ,“bin” The commands saved in the directory are available to all users |
/usr/lib | 32 Location files |
/usr/lib64 | 64 Location files |
2 File command
2.1 File base commands
- create a file
touch file1
- see file
ls // View the directory under the current directory 、 file
ls -l // View the detailed directory under the current directory 、 file
ls -i // View the directory under the current directory 、 Document number
ls -lh // View the directory under the current directory 、 File size
ls -a // Display all files
ls -ld // Look at the catalog itself
- Copy file
cp file1 file2 // Copy file1 In the same directory , name file2
cp file1 file2 dir // Copy file1 file2 To dir Under the table of contents
cp -p // Moving files , And save all the original information
- Move ( rename ) file
mv a b // Move to local , And renamed
mv a b dir // hold a,b Move to dir Catalog
- Delete file
rm a b c // Delete normal files
rm -f a b c // Force file deletion
General account rm Deleting does not prompt ,
root Prompt for administrator to delete ,y yes n no
Unless -f Mandatory deletion , Use caution
2.2 The command to view the contents of a file
- cat
cat file // View the contents of the file in positive order
tac file // Check the contents of the file in reverse order
cat -b file // The file content displays the line number
cat -A file
// View hidden content : A newline 、 Space 、 Special symbols
- nl
nl -ba file // Whether there is an empty line or not , Line numbers are listed
nl -bt file // If there is a free line , Line numbers are not listed
- less
less file
/ To find the character
:f Displays the file name and number of lines
b Turn to the first page
Space Page down
pagedown Page down
pageup Page up
q sign out
- head、tail
head file // Display the first ten lines of the file
tail file // Show the last few lines of the file , Generally, check the log ( dynamic )
Parameters
-n: Show a few lines ( Default ten rows )
-f: Dynamic display at the end of the file
- wc
wc -l file name // Display row number
wc -c file name // Display bytes
2.3 lookup 、 Replace the contents of the file
- grep
Can only be used to find the contents of a file
grep -i Happy file
Parameters
-i : View includes Happy All the lines of this word
-v : View does not contain Happy All the lines of this word
-n : Match to Happy The content of the line shows the line number
-c : see Happy There are several lines of this word
sed Can find , Then replace or insert what you want
character | Means |
---|---|
a | newly added ,a You can use a string after , And these strings will appear on a new line ( The next line at the moment ) |
d | Delete , Because it's deletion , therefore d Usually there's nothing to take back ; |
i | Insert ,i You can use a string after , And these strings will appear on a new line ( The current line ); |
p | Print , It is also about to print the selected information . Usually p And parameters sed. |
s | replace , Work that can be replaced directly ! |
- Find files find
usage :find[ route ][ Command parameter ][ expression ]
Parameters :
-name “ file name ”: Find the file with the specified name ;
-user: Find files owned by the specified user ;
-group: Find the files owned by the specified group ;
-mtimen: Find in N A document that was modified two days ago ;
-atimen: Find in N The files that were accessed a day ago ;
-type d/t/b/1/p: Find another piece of the specified type ;
-empty: Find empty files ;
-size: Search by capacity ;
-perm mode: Find the file with the specified properties ;
-exec command{
} \: Find the specified file and execute the specified command ;
-newer file name : Find a file newer than the specified file
find * // All characters
find ? // Single character
- Look up the directory which
which command
2.4 Soft connection 、 Hard links
Hard links :
- and cp -p The same meaning , however Hard links Can be updated synchronously
- You cannot hard link directories ,
- No zoning
ln
ln -l
Soft connection
ln -s: Soft connection
3 File and directory permissions
3.1 Query authority
ls -l Query details , What does each place mean
- type
d Presentation directory
– Said file
1 Express Connection file
b Represents a device file , Interface device providing storage
c Represents a device file . Provide serial interface device – keyboard ,
- jurisdiction
rwx, read 、 Write 、 perform , No authority is -
The first group rwx : file owner Authority
Second group rwx : file Subordinate to the group Authority
The third group rwx : file others Authority
- File permissions
The owner of the file is the user , No, w Permissions can also be forced to write !. The group and others do not .
r: View file contents
w: Can write
x: Sure vim edit
- Directory permissions :
The user does not have a directory w Authority , You can edit the files in this directory owned by you
r: Check the files in the directory
w:
- You can create new files and directories in this directory
- You can delete existing files and directories
- Rename existing files and directories
- Move the location of files and directories in this directory
x: Can I enter this directory
3.2 Modify the permissions
- chmod modify The owner and Subordinate to the group Authority
- Digital method :r=4,w=2, x=1
chomd 777 123
// 123 The owner of the 、 Subordinate to the group 、 The authority of others is rwx-rw-rw-
- Addition and subtraction
The owner / Subordinate to the group / others ,u / g / o , + / - / =,r / w / x
chomd u=rx 123// 123 The owner permission of is rx
chomd u+w 123 // 123 The owner permission of is rwx
- chown Modify the owner
chown root abc // modify abc The owner of is root
chown -R root abc // Recursive modification abc The owner of is root
//abc All owners of the directory are changed to root
- chgrp Modify group
groupadd Group name // New group
gpasswd -a user Group name // Field users are grouped
chgrp root abc // modify abc Is a member of root
chgrp -R root abc // Recursive modification abc Is a member of root
//abc All groups contained in the directory are changed to root
4 Default permissions
- umask: View the default permissions for the current user to create files and directories
0022: Represents the authority taken away
first 0: On behalf of special authority
022:rwxr-xr-x
When creating files and directories , Will take away the file by default x jurisdiction
- Temporarily modify the default permissions
umask 000
// When creating files and directories , file rw-rw-rw-, Catalog rwxrwxrwx
- Permanently change the default permissions ( Not recommended )
/etc/bashre // Modify the value inside
5 Special privileges
drwxrwxrwt. 14 root root 4096 10 month 23 19:32 / tmp/
rwsr- xr-x .1 root root 27832 6 month 10 2014 /usr/bin/ passwd
When s Appear in the owner's x Permission position , Indicates that the owner has SUID Authority (Set UID)
When s Appears in the x Permission position , Indicates that the group has SGID Authority (Set GID)
When t Appear in other people's x Permission position , It means that others have SBIT Authority (Sticky Bit)
- SUID, Temporarily obtain the permission of the file owner only for the file
- SGID, Even if it can work on the directory , It can also act on files
Act on documents : SUID equally
Works on the catalog : Inherit the instrument set directory a directory will continue to inherit- SBIT refer to , Only the owner of the file can delete 、 Modify the files in this directory .
Only for directory
And it can only be modified in the position of others
S and T There are upper case and lower case
Capitalized description : No, x jurisdiction
Lower case description : Yes x jurisdiction .
- SUID
- Only executable binary programs can be set SUID jurisdiction
- The command executor should have x ( perform ) The authority command executor obtains the identity of the owner of the program file when executing the program ( In the process of executing the program, the soul is attached as the owner of the document )
- SetUID Permission is only valid during the execution of the program , That is to say, identity change is only effective in the process of program execution
When it comes to execution , Temporary possession SUID jurisdiction
- SGID
1、 For documents
- Only executable binaries can be set SGID jurisdiction
- The command executor should have x Executive authority
- Command execution is when executing a program , The group identity is upgraded to the group of the program file
- SetGID Permission is also only valid during the execution of the program , That is to say, group identity change is only effective during program execution
2、 For catalog
- Normal users must have and for this directory x jurisdiction , To access this directory
- The effective group of ordinary users in this directory will become the subordinate group of this directory
- If the average user owns this directory w Authority , The default group of the new file is the group of this directory
- SBIT
- The glue bit is currently only valid for directories
- Ordinary users have w and x jurisdiction , That is, ordinary users can have write permission in this directory
- If there is no adhesive position , Because ordinary users have w jurisdiction , So you can delete all files in this directory , Include files created by other users . But it gives an adhesive bit , except root All files can be deleted , Ordinary users even have w jurisdiction , You can only delete your own files , But you can't delete files created by other users
- Modify special permissions
Digital method :SUID=4 SGID=2 SBIT=1
chomd 4777 file name
chomd 2777 file name
chomd 1777 Directory name
chmod u+s file name
chmod g+s file name
chmod o+t Directory name
- Delete special permissions
chmod 777 file name
chmod u-s file name
6 ACL File permissions
If a user in the system has permission to write to a file , But this user belongs to other, It can only be opened other Authority . But once open other Authority , every last other Can access this file ,
file ACL Permission solves this problem
acl: For a single user , Set up a single file or directory to rwx Permission modification of
- Set the acl jurisdiction setfacl
setfacl -m u: Account name : rwx file name / Directory name
// This file / Catalog Joined the acl jurisdiction , With a specific account
setfacl -m g: Group name : rwx file name / Directory name
setfacl -m m: rwx // modify mask value
Parameters
-m: To configure acl Parameters
-x: Delete a single file acl
-b: Delete acl Configuration of
-R: Recursive configuration ac Parameters
- Delete acl
setfacl -x u: Account name file name / Directory name
setfacl -x g: Account name file name / Directory name
setfacl -b file name / Directory name // Delete all of the files acl jurisdiction
- recursive ACL jurisdiction
setfacl -m u: Account name : rwx -R Directory name
- Default ACL jurisdiction
setfacl -m d:u: Account name : rwx Directory name
- Look at the file acl jurisdiction getfacl
getfacl file name / Directory name
- Maximum effective permissions mask
mask The definition of ,acl Permission limit
1、mask by Set up acl file / Catalog Maximum valid permissions for
2、 Needs and settings acl jurisdiction Meet each other Get permission , That's the file / The directory is really acl jurisdiction
7 File system hidden properties
A lock prevent root Users including users , Misoperation of documents
i: If the file is set i attribute , Deleting files is not allowed 、 Change of name , You can't add or modify data ; If the directory is set i attribute , Then you can only modify the data of files in the directory , But it's not allowed to create and delete files .
a:
If the file is set a attribute , Then you can only add data to the file , But you can't delete or modify data ; If the directory is set a attribute , Only files can be created and modified in the directory , But deleting... Is not allowed
- Set file hiding properties chattr
chattr +i file name / Directory name
chattr -i file name / Directory name
chattr =i file name / Directory name
- View file hidden properties lsattr
lsattr
Parameters
-a: Show all files and directories
-d: If the target is a directory , Show only the directory itself , Not a sub file
8 sudo jurisdiction
The shutdown command can only root The user to use , however root User is too busy , It can be given to ordinary users
- root Assign commands that can only be executed by super users to
- Common user execution .sudo The object of operation is the system command , The system command is also a file
- View the permissions granted
sudo -l
- Set up sudo
visudo // What is actually modified is /etc/sudoers file
- Example
visudo
SC ALL= /sbin/shutdown -r now // to sc The user grants restart permission
sudo /sbin/ shutdown -r now // Ordinary users perform the given permissions
边栏推荐
- Qtcreator debug code after configuring CDB debugger view variable value display card
- Go common commands
- ADC basic concepts
- Final review -php learning notes 11-php-pdo database abstraction layer
- 解决:div获取不到键盘事件
- [most complete] install MySQL on a Linux server
- DXP software uses shortcut keys
- Minecraft 1.16.5模组开发(五十) 书籍词典 (Guide Book)
- Local unloading traffic of 5g application
- Keil plug-in Usage Summary
猜你喜欢
Network security - routing principle
Local unloading traffic of 5g application
Halcon: read the camera and binary it
What if I don't know what to do after graduating from university?
Implementation of double linked list in C language
Introduction to ecostruxure (1) IEC61499 new scheme
线程池——C语言
Cubemx completes STM32F103 dual serial port 485 transceiver transmission
Variable storage unit and pointer
Ad\dxp how to solve the problem of not knowing the schematic Library
随机推荐
Proteus catalog component names and Chinese English cross reference
Go common commands
Basic knowledge of system software development
Assembly learning register
Implementation of double linked list in C language
Thread network
28 rounds of interviews with 10 companies in two and a half years
Dynamic memory management
实验一、综合实验【Process on】
Next initializesecuritycontext failed: unknown error (0x80092012) - the revocation function cannot check whether the certificate is revoked.
DS1302 digital tube clock
网络安全-ARP协议和防御
QT elementary notes
网络安全-单臂路由、DHCP中继和ICMP协议
Is it safe to open a stock account by mobile phone? What do I need to prepare for opening an account?
Starting MySQL ERROR! Couldn‘t find MySQL server (/usr/local/mysql/bin/mysqld_safe)
Introduction to ecostruxure (1) IEC61499 new scheme
STM32 register
TC397 QSPI(CPU)
JS create PDF file