linux下一般会发现有很多颜色不同的文件:

绿色: 可执行文件,可执行的程序
红色:压缩文件或者包文件
蓝色:目录
白色:一般性文件,如文本文件,配置文件,源码文件等
浅蓝色:链接文件,主要是使用ln命令建立的文件
红色闪烁:表示链接的文件有问题
黄色:表示设备文件
灰色:表示其他文件

用10位字符来代表 文件/目录 的权限
-rwxrwxrwxdrwxrwxrwx
第1位为-表示文件,为d表示目录(directory)
后面每3位分别代表用户群组其他用户的权限

root@k1:/home/temp# ll
drwxr-xr-x 2 root root 4096 Oct 27 10:49 ./
drwxr-xr-x 7 root root 4096 Oct 27 10:49 ../
-rw-r--r-- 1 root root    0 Oct 27 10:49 text.txt

u - user
g - group
o - other people (from the outside world)

可使用+添加权限:
如使用+给其他用户添加文件-rw-r--r-- 1 root root 0 Oct 27 10:49 text.txt权限:

root@k1:/home/temp# ll
-rw-r--r-- 1 root root    0 Oct 27 10:49 text.txt
root@k1:/home/temp# chmod o+w text.txt
root@k1:/home/temp# ll
-rw-r--rw- 1 root root    0 Oct 27 10:49 text.txt

相反,可使用-移除权限:
如使用-给其他用户移除文件-rw-r--rw- 1 root root 0 Oct 27 10:49 text.txt权限:

root@k1:/home/temp# ll
-rw-r--rw- 1 root root    0 Oct 27 10:49 text.txt
root@k1:/home/temp# chmod o-w text.txt
root@k1:/home/temp# ll
-rw-r--r-- 1 root root    0 Oct 27 10:49 text.txt

All right that’s simple enough but imagine that you wanted to change permissions for maybe the user the group and other people, that’s gonna take a bunch of commands and you know it's not gonna take that long, maybe a minute but we don’t have time for that. I’ll show you guys the incredibly easy way, use it to easily set all of the permissions for every group at once and you guys are gonna love it after this.

e.g.chmod 754 text.txt
7,5,4 represents the individual permissions for (in this order) user, group, other

4 stands for read
2 stands for write
1 stands for execute
0 stands for no permissions

Whenever you see a 7, that means ,for this group, they have all the permissions(read write and execute permissions).
7=4+2+1

chmod 754 text.txt means:

users which is the first one, they have seven, so they can read,write and execute.(4+2+1)
groupthey have a five, they can read and execute it.(4+1)
others they have four, so that means they can only read it.(4)

What you are going to see a lot is something like this :

chmod 777 text.txt

this means that you're giving every group all the permissions to read write and execute it.

是不是感觉不好记,心想他read凭什么就是4啊?
如果对数字比较敏感的话,现在已经猜到了,124分别是2^0,2^1,2^2

其实就是二进制,都不用专门记住read是4,write是2,execute是1。

首先要知道,二进制里面,
1代表true
0代表false

如:
将权限修改为-rwxr-xr--
userread writeexecute
groupreadexecute
ohtersread

usergroupothers
数位第1位第2位第3位第4位第5位第6位第7位第8位第9位
操作rwxrwxrwx
2进制111101100
10进制1x2^0+1x2^1+1x2^2=71x2^0+0x2^1+1x2^2=50x2^0+0x2^1+1x2^2=4

最后既是chmod 754 filename


递归修改目下的文件权限

使用-R参数,R--Recursive
e.g.

chmod -R directory
Last modification:June 2, 2023
V50%看看实力