File permissions
Run the ll command to view the description of the corresponding file and folder:
-rw-r–r– indicates the permission of this file,
The number 1 indicates the corresponding number of hard chains,
Root indicates the owning user and the second root indicates the owning group.
0/4096 indicates the corresponding file size.
August 4 xx:xx indicates the last modification event. 1. TXT indicates the file name.
-rw-r--r--
symbol | describe |
---|---|
- /d /l |
At the beginning of- It means it’s a file, at the beginningd That means this is a directory,l Indicates this is a software link |
rw- |
Represents the owner’s permissions on this file |
r-- |
Represents the group’s permission on this file |
r-- |
Represents other people’s permissions on this file |
r
Indicates that the file has read permissionread
w
Indicates that the file has the write permissionwrite
x
Indicates that the file has the executable permissionexecute
Modify basic permissions
Chmod [option] File name of the mode
Such as
-
TXT: changes the permission of 1. TXT to unreadable, unwritable, and unexecutable. 0 indicates no permission. 7 indicates the permission.
-
TXT indicates the permission of 1. TXT. U indicates the owning user, and w indicates the writable permission. U +w adds the write permission to the owning user of the current file.
-
TXT: changes the permission of 1. TXT. G indicates the owning user group, r indicates the read permission, and g+r indicates adding the read permission to the owning group of the current file.
-
TXT: changes the permission of 1. TXT. O indicates that other users have the permission to execute the file. O +x indicates that other users have the permission to execute the file.
-
options
-r means recursion.
- model
[ugoa][+-=][rwx]
Numbers can be used to specify the permissions of owners/owning groups/other users in batches.
-
Authority figures
-
4 means r is readable
-
2 means w is writable
-
1 indicates that x can be executed
-
0 indicates no permission
TXT indicates that the 1.txt file is modified, and the current user has 4+2+1 permissions. Add 1+4 read and execute permissions to the current group. Set the permissions of other users to 0(none).
Role of permissions
- The highest permissions for files are
x
, executable. - The highest permissions for directories are
w
If you have write permission on a directory, you can do anything in it.
File permissions
permissions | meaning | Example (executable command) |
---|---|---|
r |
Reading file contents | cat more head tail |
w |
Edit, add, modify the contents of the file,You cannot delete files unless you have write permission on the directory | vi echo |
x |
Indicates that the file is executable |
Under Linux, files can be executed using./[file]. Or use sh [filename] to execute the file as an execution script (which has the same effect as a./). You can execute this file as long as you have permissions.
Note that./hello requires x permissions on the file, while sh hello does not require executable permissions.
The directory permissions
permissions | meaning | The sample |
---|---|---|
r |
You can view the file name in the directory | ls |
w |
Has the permission to modify the directory structure, such as creating, deleting, and renaming files and directories in this directory | touch rm mv cp |
x |
Indicates that the directory can be accessed | cd |
Other Permission Commands
chown
Modify the file owner so that the user has all permissions on the file, 7 permissions.
Chown [user name] [file name]
Indicates that the file belongs to the user.- If you want a user to have it
7
Permission, you can takeChange the file owner to this user name.
Chown 755 Folder chown Wang. haoyu Folder Change the folder to the owner of user Wang. haoyu.Copy the code
CHGRP [group name] [file name]
Change the file to belong to this group,
Example Modify the permission of the owning group of a file.
The default permissions
umask
-
The umask command displays default permissions.
-
0022 — The default permission is 0022
- The first
0
File special permission 022
Default file permissions
- The first
File permissions
- The default permissions are those that the file has as soon as it is created.
- File cannot create an executable file by default. You must manually assign an executable file to the file.
- The file has the maximum default permission
666
- Default permissions need to be converted to letters in the subtraction
- The default permission after the resume file is
666
Minus theumask
The value of the.
For example, umask 0022 in the figure above indicates that when I create a file, the default permission is 666-002, that is, 664. The owner of the file has read and write permission, the group of the file has read and write permission, and other users only have read permission.
The directory permissions
-
The default directory permission is 777
-
The default permission after the resume directory is 777 minus the umask value