Linux is inherited from Unix, and has been designed as a multi-user system. Let's illustrate it with actual examples.
~ /Test $ ls-l
-Rw-r -- 1 Yuanyuan yu1_0 a.txt
Drwxr-xr-x 2 Yuanyuan YuanYi 4096 B
The displayed information is represented by columns: file attributes, number of links (inode), owner, and group) file Size, latest modification date, and file (directory) Name.
1. File Attributes
A file or directory has 10 basic attributes, with 1st representing the type. The last nine attributes are divided into three groups, indicating the execution attributes of owner, group, and others respectively.
File Type: [d] Directory; [-] file; [l] link file ;...
Execution attribute: [r] readable; [w] writable; [x] executable.
-Rw-r -- 1 Yuanyuan yu1_0 a.txt
Indicates that the file owner can read/write (rw), user group (group), and other users (other) read-only (r ). You can also use numbers to represent r = 4, w = 2, x = 1, for example, rw-r -- = 644.
~ /Test $ ls-l
-Rw-r -- 1 Yuanyuan yu1_0 a.txt
Drwxr-xr-x 2 Yuanyuan YuanYi 4096 B
~ /Test $ chmod 664./a.txt
~ /Test $ ls-l
-Rw-r -- 1 Yuanyuan yu1_0 a.txt
Drwxr-xr-x 2 Yuanyuan YuanYi 4096 B
Of course, we can also use more intuitive parameters.
~ /Test $ chmod a + w a.txt # Set all to writable
~ /Test $ ls-l
-Rw-1 yustmyu1_0 a.txt
Drwxr-xr-x 2 Yuanyuan YuanYi 4096 B
~ /Test $ chmod ug = rw, o = r a.txt # The owner and group can read and write, and other read-only
~ /Test $ ls-l
-Rw-r -- 1 Yuanyuan yu1_0 a.txt
Drwxr-xr-x 2 Yuanyuan YuanYi 4096 B
~ /Test $ chmod u = rw, g-w a.txt # The owner can read and write the group.
~ /Test $ ls-l
-Rw-r -- 1 Yuanyuan yu1_0 a.txt
Drwxr-xr-x 2 Yuanyuan YuanYi 4096 B
Parameter description:
(1) u = owner; g = group; o = other; a = u + g + o
(2) [=] settings; [-] Remove; [+] add.
For a directory, r indicates the permission to read the directory structure, w indicates that you can create, delete, and move files and subdirectories in the directory, and x indicates that you can enter the directory.
~ /Test $ ls-l
-Rw-r -- 1 Yuanyuan yu1_0 a.txt
Drwxr-xr-x 2 Yuanyuan YuanYi 4096 B
~ /Test $ chmod a-x./B # Remove x
~ /Test $ ls-l
-Rw-r -- 1 Yuanyuan yu1_0 a.txt
Drw-r -- 2 Yuanyuan YuanYi 4096 B
~ /Test $ cd B # unable to enter this directory
-Bash: cd: B: Permission denied
~ /Test $ chmod a + x B # restore
~ /Test $ ls-l
-Rw-r -- 1 Yuanyuan yu1_0 a.txt
Drwxr-xr-x 2 Yuanyuan YuanYi 4096 B
~ /Test $ cd B # enter correctly
Chmod supports the-R parameter to recursively modify all files and subdirectories in the directory.
In addition to the above basic attributes, you can also use chattr and lsattr to set and display hidden attributes.
- Four pages in total:
- Previous Page
- 1
- 2
- 3
- 4
- Next Page