玩转并理解linux中的文件/目录的rwx权限
来源:互联网 发布:视频动画软件手里 编辑:程序博客网 时间:2024/05/16 07:02
linux是一个相对安全的系统, 其中的权限更是无处不在。 在本文中, 我们来谈谈linux中的文件/目录的rwx权限。 为了简便起见, 我们仅仅以文件owner的rwx为例。
一. 文件的rwx权限分别是什么意思?
1. r权限:可读权限, 验证如下:
[taoge@localhost learn_c]$ ls -l
total 0
[taoge@localhost learn_c]$ echo hello > a.txt
[taoge@localhost learn_c]$ ls -l
total 4
-rw-rw-r-- 1 taoge taoge 6 May 6 03:51 a.txt
[taoge@localhost learn_c]$ chmod 000 a.txt
[taoge@localhost learn_c]$ ls -l
total 4
---------- 1 taoge taoge 6 May 6 03:51 a.txt
[taoge@localhost learn_c]$ cat a.txt
cat: a.txt: Permission denied
[taoge@localhost learn_c]$ chmod u+r a.txt
[taoge@localhost learn_c]$ ls -l
total 4
-r-------- 1 taoge taoge 6 May 6 03:51 a.txt
[taoge@localhost learn_c]$ cat a.txt
hello
[taoge@localhost learn_c]$
total 0
[taoge@localhost learn_c]$ echo hello > a.txt
[taoge@localhost learn_c]$ ls -l
total 4
-rw-rw-r-- 1 taoge taoge 6 May 6 03:51 a.txt
[taoge@localhost learn_c]$ chmod 000 a.txt
[taoge@localhost learn_c]$ ls -l
total 4
---------- 1 taoge taoge 6 May 6 03:51 a.txt
[taoge@localhost learn_c]$ cat a.txt
cat: a.txt: Permission denied
[taoge@localhost learn_c]$ chmod u+r a.txt
[taoge@localhost learn_c]$ ls -l
total 4
-r-------- 1 taoge taoge 6 May 6 03:51 a.txt
[taoge@localhost learn_c]$ cat a.txt
hello
[taoge@localhost learn_c]$
2. w权限: 可写权限, 验证如下:
[taoge@localhost learn_c]$ ls -l
total 0
[taoge@localhost learn_c]$ touch a.txt
[taoge@localhost learn_c]$ ls -l
total 0
-rw-rw-r-- 1 taoge taoge 0 May 6 03:56 a.txt
[taoge@localhost learn_c]$ chmod 000 a.txt
[taoge@localhost learn_c]$ ls -l
total 0
---------- 1 taoge taoge 0 May 6 03:56 a.txt
[taoge@localhost learn_c]$ chmod u+w a.txt
[taoge@localhost learn_c]$ ls -l
total 0
--w------- 1 taoge taoge 0 May 6 03:56 a.txt
[taoge@localhost learn_c]$ echo hello > a.txt
[taoge@localhost learn_c]$ cat a.txt
cat: a.txt: Permission denied
[taoge@localhost learn_c]$ chmod u+r a.txt
[taoge@localhost learn_c]$ cat a.txt
hello
[taoge@localhost learn_c]$
total 0
[taoge@localhost learn_c]$ touch a.txt
[taoge@localhost learn_c]$ ls -l
total 0
-rw-rw-r-- 1 taoge taoge 0 May 6 03:56 a.txt
[taoge@localhost learn_c]$ chmod 000 a.txt
[taoge@localhost learn_c]$ ls -l
total 0
---------- 1 taoge taoge 0 May 6 03:56 a.txt
[taoge@localhost learn_c]$ chmod u+w a.txt
[taoge@localhost learn_c]$ ls -l
total 0
--w------- 1 taoge taoge 0 May 6 03:56 a.txt
[taoge@localhost learn_c]$ echo hello > a.txt
[taoge@localhost learn_c]$ cat a.txt
cat: a.txt: Permission denied
[taoge@localhost learn_c]$ chmod u+r a.txt
[taoge@localhost learn_c]$ cat a.txt
hello
[taoge@localhost learn_c]$
3. x权限:可执行权限, 验证如下:
[taoge@localhost learn_c]$ ls -l
total 4
-rw-rw-r-- 1 taoge taoge 65 May 6 04:02 test.c
[taoge@localhost learn_c]$ cat test.c
#include <stdio.h>
int main()
{
printf("good\n");
return 0;
}
[taoge@localhost learn_c]$ gcc test.c
[taoge@localhost learn_c]$ ls -l
total 12
-rwxrwxr-x 1 taoge taoge 4638 May 6 04:04 a.out
-rw-rw-r-- 1 taoge taoge 65 May 6 04:02 test.c
[taoge@localhost learn_c]$ ./a.out
good
[taoge@localhost learn_c]$ chmod 000 a.out
[taoge@localhost learn_c]$ ./a.out
bash: ./a.out: Permission denied
[taoge@localhost learn_c]$ chmod u+x a.out
[taoge@localhost learn_c]$ ./a.out
good
[taoge@localhost learn_c]$
total 4
-rw-rw-r-- 1 taoge taoge 65 May 6 04:02 test.c
[taoge@localhost learn_c]$ cat test.c
#include <stdio.h>
int main()
{
printf("good\n");
return 0;
}
[taoge@localhost learn_c]$ gcc test.c
[taoge@localhost learn_c]$ ls -l
total 12
-rwxrwxr-x 1 taoge taoge 4638 May 6 04:04 a.out
-rw-rw-r-- 1 taoge taoge 65 May 6 04:02 test.c
[taoge@localhost learn_c]$ ./a.out
good
[taoge@localhost learn_c]$ chmod 000 a.out
[taoge@localhost learn_c]$ ./a.out
bash: ./a.out: Permission denied
[taoge@localhost learn_c]$ chmod u+x a.out
[taoge@localhost learn_c]$ ./a.out
good
[taoge@localhost learn_c]$
二. 目录的rwx权限分别是什么意思?
1. r权限:可读权限(可列举查看目录下的内容), 验证如下:
[taoge@localhost learn_c]$ ls -l
total 0
total 0
[taoge@localhost learn_c]$ mkdir test
[taoge@localhost learn_c]$ ls -l
total 4
drwxrwxr-x 2 taoge taoge 4096 May 6 04:07 test
[taoge@localhost learn_c]$ touch ./test/a.txt
[taoge@localhost learn_c]$ ls ./test/
a.txt
[taoge@localhost learn_c]$ chmod u-r test/
[taoge@localhost learn_c]$ ls ./test/
ls: cannot open directory ./test/: Permission denied
[taoge@localhost learn_c]$
[taoge@localhost learn_c]$ ls -l
total 4
drwxrwxr-x 2 taoge taoge 4096 May 6 04:07 test
[taoge@localhost learn_c]$ touch ./test/a.txt
[taoge@localhost learn_c]$ ls ./test/
a.txt
[taoge@localhost learn_c]$ chmod u-r test/
[taoge@localhost learn_c]$ ls ./test/
ls: cannot open directory ./test/: Permission denied
[taoge@localhost learn_c]$
2. w权限:可写权限(可以往目录中写东东, 比如文件), 验证如下:
[taoge@localhost learn_c]$ ls -l
total 0
[taoge@localhost learn_c]$ mkdir test
[taoge@localhost learn_c]$ ls -l
total 4
drwxrwxr-x 2 taoge taoge 4096 May 6 04:13 test
[taoge@localhost learn_c]$ touch ./test/a.txt
[taoge@localhost learn_c]$ chmod u-w test
[taoge@localhost learn_c]$ touch ./test/b.txt
touch: cannot touch `./test/b.txt': Permission denied
[taoge@localhost learn_c]$
total 0
[taoge@localhost learn_c]$ mkdir test
[taoge@localhost learn_c]$ ls -l
total 4
drwxrwxr-x 2 taoge taoge 4096 May 6 04:13 test
[taoge@localhost learn_c]$ touch ./test/a.txt
[taoge@localhost learn_c]$ chmod u-w test
[taoge@localhost learn_c]$ touch ./test/b.txt
touch: cannot touch `./test/b.txt': Permission denied
[taoge@localhost learn_c]$
[taoge@localhost learn_c]$ ls -l
total 0
[taoge@localhost learn_c]$ mkdir test
[taoge@localhost learn_c]$ ls -l
total 4
drwxrwxr-x 2 taoge taoge 4096 May 6 04:17 test
[taoge@localhost learn_c]$ cd test/
[taoge@localhost test]$ cd -
/home/taoge/Desktop/learn_c
[taoge@localhost learn_c]$ chmod u-x test/
[taoge@localhost learn_c]$ cd test/
bash: cd: test/: Permission denied
[taoge@localhost learn_c]$
total 0
[taoge@localhost learn_c]$ mkdir test
[taoge@localhost learn_c]$ ls -l
total 4
drwxrwxr-x 2 taoge taoge 4096 May 6 04:17 test
[taoge@localhost learn_c]$ cd test/
[taoge@localhost test]$ cd -
/home/taoge/Desktop/learn_c
[taoge@localhost learn_c]$ chmod u-x test/
[taoge@localhost learn_c]$ cd test/
bash: cd: test/: Permission denied
[taoge@localhost learn_c]$
[taoge@localhost learn_c]$ ls -l
total 0
[taoge@localhost learn_c]$ mkdir test
[taoge@localhost learn_c]$ touch ./test/a.txt ./test/b.txt ./test/c.txt ./test/d.txt
[taoge@localhost learn_c]$ ls -l
total 4
drwxrwxr-x 2 taoge taoge 4096 May 6 04:33 test
[taoge@localhost learn_c]$ chmod u-r test/
[taoge@localhost learn_c]$ touch ./test/e.txt
[taoge@localhost learn_c]$ chmod u-w test/
[taoge@localhost learn_c]$ touch ./test/f.txt
touch: cannot touch `./test/f.txt': Permission denied
[taoge@localhost learn_c]$ rm ./test/a.txt
rm: cannot remove `./test/a.txt': Permission denied
[taoge@localhost learn_c]$ chmod u+w test/
[taoge@localhost learn_c]$ chmod u-x test/
[taoge@localhost learn_c]$ touch ./test/f.txt
touch: cannot touch `./test/f.txt': Permission denied
[taoge@localhost learn_c]$ rm ./test/a.txt
rm: cannot remove `./test/a.txt': Permission denied
[taoge@localhost learn_c]$ chmod u+x test/
[taoge@localhost learn_c]$
total 0
[taoge@localhost learn_c]$ mkdir test
[taoge@localhost learn_c]$ touch ./test/a.txt ./test/b.txt ./test/c.txt ./test/d.txt
[taoge@localhost learn_c]$ ls -l
total 4
drwxrwxr-x 2 taoge taoge 4096 May 6 04:33 test
[taoge@localhost learn_c]$ chmod u-r test/
[taoge@localhost learn_c]$ touch ./test/e.txt
[taoge@localhost learn_c]$ chmod u-w test/
[taoge@localhost learn_c]$ touch ./test/f.txt
touch: cannot touch `./test/f.txt': Permission denied
[taoge@localhost learn_c]$ rm ./test/a.txt
rm: cannot remove `./test/a.txt': Permission denied
[taoge@localhost learn_c]$ chmod u+w test/
[taoge@localhost learn_c]$ chmod u-x test/
[taoge@localhost learn_c]$ touch ./test/f.txt
touch: cannot touch `./test/f.txt': Permission denied
[taoge@localhost learn_c]$ rm ./test/a.txt
rm: cannot remove `./test/a.txt': Permission denied
[taoge@localhost learn_c]$ chmod u+x test/
[taoge@localhost learn_c]$
因此, 如果某一目录test删除不掉, 很可能是因为其中有不可删除的文件, 从本质上来讲, 就是test自己没有wx权限了。
好, 本文先闲谈到这里。
0 0
- 玩转并理解linux中的文件/目录的rwx权限
- LINUX文件与目录的RWX权限
- Linux文件与目录的rwx权限
- Linux对文件目录rwx权限的总结
- Linux系统文件目录权限详解 - rwx
- Linux入门:rwx权限在目录和文件中的区别
- linux文件与目录默认权限及rwx对应的表现
- linux RWX权限的解读
- linux RWX权限的解读
- linux RWX权限的解读
- linux系统修改文件的读写执行rwx的权限
- Linux 文件权限管理 之 RWX
- Unix/Linux目录权限: rwx 之外的 s..在svngetlock时提示权限不足,给相关目录lock目录权限。。
- 文件及文件夹rwx权限的意义
- Linux学习之权限管理命令&&深入理解rwx权限
- Linux系统中文件和目录的rwx权限的区别
- linux 权限详解rwx
- linux权限rwx
- Java 基础 第七天
- java解析xml的几种方式
- JavaScript原型重写的问题注意
- 看图学英语之snip
- android之wifi开发(一)
- 玩转并理解linux中的文件/目录的rwx权限
- 设计模式(五)之工厂方法模式
- 那些大多数人都不愿承认的事实
- Spark MLlib Linear Regression线性回归算法
- java读取properties文件
- String与InputStream互转的几种方法
- HTML DOM cursor 属性
- poj 2449 Remmarguts' Date(第K短路 A*)
- 项目创建到github各种命令使用