博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
文件和目录权限chmod、更改所有者和所属组chown、umask、隐藏权限lsattr/chattr
阅读量:7108 次
发布时间:2019-06-28

本文共 1818 字,大约阅读时间需要 6 分钟。

文件和目录权限chmod

1、

权限范围:

u :目录或者文件的当前的用户

g :目录或者文件的当前的群组

o :除了目录或者文件的当前用户或群组之外的用户或者群组

a :所有的用户及群组

权限代号:

r :读权限,用数字4表示

w :写权限,用数字2表示

x :执行权限,用数字1表示

- :删除权限,用数字0表示

s :特殊权限 

[root@test ~]# chmod 700 anaconda-ks.cfg 

You have new mail in /var/spool/mail/root

[root@test ~]# ls -la anaconda-ks.cfg 

-rwx------. 1 root root 1096 Sep  3 07:27 anaconda-ks.cfg

-R:表示递归

[root@test ~]# chmod 755 -R /opt/

[root@test ~]# ls -la /opt/

total 286660

drwxr-xr-x.  7 root root      4096 Oct 23 09:55 .

dr-xr-xr-x. 28 root root      4096 Oct 20 16:41 ..

-rwxr-xr-x   1 test test      6555 Oct 16 17:13 percona-release-0.1-4.noarch.rpm

drwxr-xr-x  17 test test      4096 Oct 10 22:48 Python-2.7.6

更改所有者和所属组chown

-R:表示有目录的情况下

[root@test ~]# chown -R root.root *

You have new mail in /var/spool/mail/root

[root@test ~]# ll

total 2352

-rwx------. 1 root root    1096 Sep  3 07:27 anaconda-ks.cfg

drwxr-xr-x  3 root root    4096 Oct 11 05:01 conf

-rw-r--r--  1 root root    3523 Sep 18 15:12 file.txt

-rw-r--r--  1 root root 1595408 Nov  7  2016 get-pip.py

-rw-r--r--. 1 root root    9795 Sep  3 07:27 install.log

-rw-r--r--. 1 root root    3091 Sep  3 07:26 install.log.syslog

umask

1、查看

[root@test ~]# umask 

0022

2、当umask为偶数时:

默认情况下的umask值是022(可以用umask命令查看),此时你建立的文件默认权限是644(6-0,6-2,6-2),建立的目录的默认权限是755(7-0,7-2,7-2)

3、当umask为基数时:

相减后加上1

如:umask 051

666 - 051=615;加上1:变为626的权限

文件:

[root@test ~]# touch 1.txt

[root@test ~]# ls -la 1.txt 

-rw--w-rw- 1 root root 0 Oct 23 11:41 1.txt

文件夹(777-051=726):

[root@test ~]# ls -ld tt/

drwx-w-rw- 2 root root 4096 Oct 23 11:44 tt/

隐藏权限lsattr/chattr

charrt

改变文件属性

-i:不能编更改文件和目录,即使root也不行

[root@test ~]# chmod 777 1.txt

chmod: changing permissions of `1.txt': Operation not permitted

-a:只能追加操作,不能直接编辑文件vi

[root@test ~]# echo '123123' >> 1.txt

lsattr 1.txt

查看权限

取消:

chattr -i  1.txt

本文转自 iekegz 51CTO博客,原文链接:http://blog.51cto.com/jacksoner/1975185,如需转载请自行联系原作者
你可能感兴趣的文章
nginx前后端分离
查看>>
mysql忘记密码后如何重置??
查看>>
Bind 9.8 配置 自己动手
查看>>
uWSGI 配置指令介绍
查看>>
ubuntu解压rar文件
查看>>
ORA-00845: MEMORY_TARGET not supported on this system报错解决
查看>>
如何用PLSQL Developer登陆远程服务器
查看>>
启动mac自带的apache服务器,并打开支持的php模块
查看>>
js中用正则表达式 过滤特殊字符, js验证中文字母数字
查看>>
"永恒之蓝"勒索软件病毒防范方法及措施
查看>>
我的友情链接
查看>>
CIO如何在企业并购中生存
查看>>
我的友情链接
查看>>
linux系统最小化安装原则
查看>>
【Yii2-CookBook】JSON 和 XML 输出
查看>>
PDF 解密
查看>>
SQL Server 2005客户端安装和端口设置
查看>>
Linux安装PPS(知已知彼、百战不殆)
查看>>
如何使用Apache HTTP Server?(window)
查看>>
GoldenGate版本兼容知识汇总
查看>>