linux下一般会发现有很多颜色不同的文件:
绿色: 可执行文件,可执行的程序
红色:压缩文件或者包文件
蓝色:目录
白色:一般性文件,如文本文件,配置文件,源码文件等
浅蓝色:链接文件,主要是使用ln命令建立的文件
红色闪烁:表示链接的文件有问题
黄色:表示设备文件
灰色:表示其他文件
用10位字符来代表 文件/目录 的权限
如-rwxrwxrwx
或drwxrwxrwx
第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 forread
2
stands forwrite
1
stands forexecute
0
stands forno 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)
group
they 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--
让user
可read
write
并execute
,
让group
可read
和execute
,
让ohters
仅read
。
user | group | others | ||||||||
数位 | 第1位 | 第2位 | 第3位 | 第4位 | 第5位 | 第6位 | 第7位 | 第8位 | 第9位 | |
操作 | r | w | x | r | w | x | r | w | x | |
2进制 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 0 | 0 | |
10进制 | 1x2^0+1x2^1+1x2^2=7 | 1x2^0+0x2^1+1x2^2=5 | 0x2^0+0x2^1+1x2^2=4 |
最后既是chmod 754 filename
递归修改目下的文件权限
使用-R
参数,R
--Recursive
e.g.
chmod -R directory