16. Linux 文件目录权限

简介: 16. Linux 文件目录权限# 文件参数d:表示是一个目录-:表示这是一个普通的文件l: 表示这是一个符号链接文件,实际上它指向另一个文件b、c:分别表示区块设备和其他的外围设备,是特殊类型的文件s、p:这些文件关系到系统的数据结构和管道...
16. Linux 文件目录权限
# 文件参数
d:表示是一个目录
-:表示这是一个普通的文件
l: 表示这是一个符号链接文件,实际上它指向另一个文件
bc:分别表示区块设备和其他的外围设备,是特殊类型的文件
sp:这些文件关系到系统的数据结构和管道
:执行文件或者进入目录的权限

一、将一个文件设置成其他人不能读
# 先用 root 用户修改一个文件的权限:
[root@Demon data]# touch 1.txt
[root@Demon data]# ls -lh
总用量 4.0K
-rw-r--r--. 1 root root    0 1月  15 19:54 1.txt
[root@Demon data]# chmod 600 1.txt
[root@Demon data]# ls -l
总用量 4
-rw-------. 1 root root    0 1月  15 19:54 1.txt
# 用demon 用户打开文件:
demon@Demon data]$ cat 1.txt
cat: 1.txt: 权限不够

二、将一个目录设置成其它人不可进入
# 还是先用 root 对 /data/test 目录进行操作
[root@Demon data]# chmod 744 test
[root@Demon data]# ls -l
总用量 8
drwxr--r--. 2 root root 4096 1月  15 20:00 test
# 用 demon 用户进入 /data/test 目录
[demon@Demon data]$ cd test/
bash: cd: test/: 权限不够

三、将一个脚本设置成不可执行
[demon@Demon data]$ ls -l test.sh
-rwxrwxr-x. 1 D D 26 1月  15 20:07 test.sh
[demon@Demon data]$ ./test.sh
Demon
[demon@Demon data]$ chmod 666 test.sh
[demon@Demon data]$ ./test.sh
bash: ./test.sh: 权限不够

四、改变文件 / 目录的所有者
  chown root /u 将 /u 的属主更改为"root"。
  chown root:staff /u 和上面类似,但同时也将其属组更改为"staff"。
  chown -hR root /u         将 /u 及其子目录下所有文件的属主更改为"root"。

1、改变文件的所有者
[root@Demon data]# ls -l 1.txt
-rw-------. 1 root root 0 1月  15 19:54 1.txt
[root@Demon data]# chown demon  1.txt
[root@Demon data]# ls -l 1.txt
-rwxrw-rw-. 1 demon  root 0 1月  15 19:54 1.txt

2、改变目录的所有者
[root@Demon data]# ls -l
总用量 12
drwxr--r--. 2 root root 4096 1月  15 20:00 test
[root@Demon data]# chown demon test
[root@Demon data]# ls -l
总用量 12
drwxr--r--. 2 demon     root 4096 1月  15 20:00 test
相关文章
|
4天前
|
Linux 开发工具
Linux E325: 注意 发现交换文件 “*.swp“
Linux E325: 注意 发现交换文件 “*.swp“
13 0
|
21小时前
|
Linux
如何在 Linux 中递归更改文件的权限?
【5月更文挑战第10天】
12 3
|
1天前
|
Linux
Linux如何查询较大文件的方法
【5月更文挑战第8天】Linux如何查询较大文件的方法
5 0
|
1天前
|
Linux 程序员 Shell
【Linux】详解core dump文件的作用以及用法&&ubuntu20.04下无法形成core dump文件的解决办法
【Linux】详解core dump文件的作用以及用法&&ubuntu20.04下无法形成core dump文件的解决办法
|
2天前
|
Linux Shell
Linux操作系统下查找大文件或目录的技巧
Linux操作系统下查找大文件或目录的技巧
10 2
|
2天前
|
算法 Linux 数据安全/隐私保护
Linux:权限
Linux:权限
9 0
|
2天前
|
算法 Linux
Linux:文件增删 & 文件压缩指令
Linux:文件增删 & 文件压缩指令
6 0
|
2天前
|
域名解析 Unix Linux
AIX上如何正确挂载Linux 的nfs共享目录分享篇
AIX上如何正确挂载Linux 的nfs共享目录分享篇
|
3天前
|
Linux 数据安全/隐私保护 Windows
【Linux】权限 !
关于Linux的权限问题,可以理解为不同级别的工作者,分别拥有不同的能力来管理文件。
19 5
|
3天前
|
Linux 开发工具 数据安全/隐私保护
深入探索Linux:ACL权限、特殊位与隐藏属性的奥秘
深入探索Linux:ACL权限、特殊位与隐藏属性的奥秘