bash - 为什么 chmod 上的递归模式除了递归之外什么都做?

标签 bash unix centos chmod

chmod -R 775 *.cgi 只更改当前目录中文件的权限,子目录中的文件根本不会被修改。这与简单地执行 chmod 775 *.cgi 的功能完全相同。我见过人们使用诸如 find 之类的解决方案。很好,但是如果 -R 模式什么都没有完成,为什么还要存在呢?

最佳答案

可能是因为您没有名为*.cgi 的目录。 manual :

-R Recursively change file mode bits. For each file operand that names a directory, chmod shall change the file mode bits of the directory and all files in the file hierarchy below it.

例如:

$ ls -R
.:
a  a.c  b.c  c.c

./a:
a.c  b.c  sub

./a/sub:
a.c  b.c  
$ chmod -R 444 *.c
$ ls -l
drwxr-xr-x 3 msw msw 4096 2010-08-12 18:07 a
-r--r--r-- 1 msw msw    0 2010-08-12 18:07 a.c
-r--r--r-- 1 msw msw    0 2010-08-12 18:07 b.c
-r--r--r-- 1 msw msw    0 2010-08-12 18:07 c.c
$ : directory a not affected
$ chmod -R u-w a    
$ ls -l a
-r-xr-xr-x 1 msw msw    0 2010-08-12 18:07 a.c
-r-xr-xr-x 1 msw msw    0 2010-08-12 18:07 b.c
dr-xr-xr-x 3 msw msw 4096 2010-08-12 18:07 sub
$ ls -l a/sub
-r-xr-xr-x 1 msw msw    0 2010-08-12 18:07 a.c
-r-xr-xr-x 1 msw msw    0 2010-08-12 18:07 b.c
$ : got em

关于bash - 为什么 chmod 上的递归模式除了递归之外什么都做?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3472383/

相关文章:

php - 将文件从一台服务器保存到另一台服务器

ruby - rvm 在 centos 5.5 上安装 1.8.7-head 错误

linux - 安装两次后supervisor centos故障排除,有2种不同的方法

c - 将 2 个文件编译成一个使用 C 中的 math.h 库的 exe 的命令行是什么

linux - bash 查找至少包含一个数组元素的行

python - 从多个文件中抓取行的最快方法

c++ - 即使连接不再可用,发送也会成功?

bash - tr -d [=,=] 的作用是什么?

bash - 如何定义一个 shell 脚本变量以在脚本之外具有作用域

linux - 可以使用与管道命令的输出相同的输入文件吗?