Linux文件有rwx即读、写、执行三种权限
管理文件权限
文件访问权限:rwxrwxrwx (777)
权限数值化后:(7)(7)(7)
r 读 -4 允许用户打开、浏览文件内容
w 写 -2 允许用户打开、编辑文件
x 执行 -1 允许用户执行
新创建文件默认权限为rw-r--r-- (644)
默认文件权限根据umask值设置(默认为022)
新文件权限为rw-r-r(644)
666 – 022 = rw-r--r--
新创建目录默认权限为rwxr-xr-x (755)
默认目录权限根据umask值设置(默认为022)
新目录权限为rwxr-xr-x
777 - 022 = rwxr-xr-x
umask
修改权限:chmod
添加、删除文件或目录状态
chmod u+x
chmod u=rwx,g=rw,o=r chmod 764
chmod o-r hello.txt
chmod a+x test 给所有用户other赋予执行权限(生产服务器不推荐给所有用户都赋予执行权限)
chmod u+x test 给当前用户other赋予执行权限
chmod g+x test 给同组用户other赋予执行权限
chmod o+x test 给其他用户other赋予执行权限
chmod +x test 默认是给所有用户赋予执行权限
chmod -x test 默认是给所有用户取消执行权限
去掉相应权限用-,例如:
chmod a-x test 给所有用户other去除执行权限
指定权限用=,例如:
chmod u=rwx test 指定当前用户拥有读写执行权限
实例:
[root@RHEL7x64 ~]# ll
总用量 4
-rw-------. 1 root root 1209 6月 24 16:15 anaconda-ks.cfg
[root@RHEL7x64 ~]# touch test
[root@RHEL7x64 ~]# ll
总用量 4
-rw-------. 1 root root 1209 6月 24 16:15 anaconda-ks.cfg
-rw-r--r--. 1 root root 0 6月 27 17:44 test
[root@RHEL7x64 ~]# chmod u+x test
[root@RHEL7x64 ~]# ll
总用量 4
-rw-------. 1 root root 1209 6月 24 16:15 anaconda-ks.cfg
-rwxr--r--. 1 root root 0 6月 27 17:44 test
[root@RHEL7x64 ~]# chmod o+x test
[root@RHEL7x64 ~]# ll
总用量 4
-rw-------. 1 root root 1209 6月 24 16:15 anaconda-ks.cfg
-rwxr--r-x. 1 root root 0 6月 27 17:44 test
[root@RHEL7x64 ~]# chmod g+x test
[root@RHEL7x64 ~]# ll
总用量 4
-rw-------. 1 root root 1209 6月 24 16:15 anaconda-ks.cfg
-rwxr-xr-x. 1 root root 0 6月 27 17:44 test
[root@RHEL7x64 ~]# chmod a-x test
[root@RHEL7x64 ~]# ll
总用量 4
-rw-------. 1 root root 1209 6月 24 16:15 anaconda-ks.cfg
-rw-r--r--. 1 root root 0 6月 27 17:44 test
[root@RHEL7x64 ~]# chmod a+x test
[root@RHEL7x64 ~]# ll
总用量 4
-rw-------. 1 root root 1209 6月 24 16:15 anaconda-ks.cfg
-rwxr-xr-x. 1 root root 0 6月 27 17:44 test
[root@RHEL7x64 ~]#
[root@RHEL7x64 ~]# ll
总用量 8
-rw-------. 1 root root 1209 6月 24 16:15 anaconda-ks.cfg
-rw-r--r--. 1 root root 1915 7月 2 16:07 memtop.sh
-rwxr-xr-x. 1 root root 0 6月 27 17:44 test
[root@RHEL7x64 ~]# chmod +x memtop.sh
[root@RHEL7x64 ~]# ll
总用量 8
-rw-------. 1 root root 1209 6月 24 16:15 anaconda-ks.cfg
-rwxr-xr-x. 1 root root 1915 7月 2 16:07 memtop.sh
-rwxr-xr-x. 1 root root 0 6月 27 17:44 test
[root@RHEL7x64 ~]# chmod -x memtop.sh
[root@RHEL7x64 ~]# ll
总用量 8
-rw-------. 1 root root 1209 6月 24 16:15 anaconda-ks.cfg
-rw-r--r--. 1 root root 1915 7月 2 16:07 memtop.sh
-rwxr-xr-x. 1 root root 0 6月 27 17:44 test
[root@RHEL7x64 ~]# chmod u+x memtop.sh
[root@RHEL7x64 ~]# ll
总用量 8
-rw-------. 1 root root 1209 6月 24 16:15 anaconda-ks.cfg
-rwxr--r--. 1 root root 1915 7月 2 16:07 memtop.sh
-rwxr-xr-x. 1 root root 0 6月 27 17:44 test
[root@RHEL7x64 ~]#
linux下chmod赋权详解
猜你喜欢
转载自zhitangrui2010.iteye.com/blog/2272156
今日推荐
周排行