LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 690|回复: 7

怎样实现这样的功能

[复制链接]
发表于 2007-1-16 16:51:13 | 显示全部楼层 |阅读模式
将一个目录下所有的文件权限改成644,而把所有的子目录权限改成755?

我试着用过find分别列出目录和文件,然后下一步不知道怎么处理,因为会遇到文件名或者目录名中有空格的情况,直接用xargs传给chmod的话会有问题。
发表于 2007-1-16 17:37:31 | 显示全部楼层
find -print0 | xargs -0

zsh -c 'chmod 755 ./**/.*(/)'
zsh -c 'chmod 644 ./**/.*(.)'
回复 支持 反对

使用道具 举报

发表于 2007-1-16 17:42:51 | 显示全部楼层
第一个是大道,后一个zsh法是小巧。
回复 支持 反对

使用道具 举报

发表于 2007-1-16 18:04:02 | 显示全部楼层
admire
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-1-17 09:22:01 | 显示全部楼层
非常感谢!以前不知道有-0这个选项
回复 支持 反对

使用道具 举报

发表于 2007-1-18 10:46:38 | 显示全部楼层
man xargs, 呵呵

NAME
       xargs - build and execute command lines from standard input
..........
       --null, -0
              Input items are terminated by a null character instead of by whitespace, and the quotes and  backslash  are  not
              special  (every character is taken literally).  Disables the end of file string, which is treated like any other
              argument.  Useful when input items might contain white space, quote marks, or backslashes.  The GNU find -print0
              option produces input suitable for this mode.
回复 支持 反对

使用道具 举报

发表于 2007-1-18 10:54:15 | 显示全部楼层
再来个相对的:


  1. man find:
  2.   ...
  3.        -print0
  4.               True;  print  the full file name on the standard output, followed by a
  5.               null character (instead of the newline character that ‘-print’  uses).
  6.               This  allows  file names that contain newlines or other types of white
  7.               space to be correctly interpreted by programs that  process  the  find
  8.               output.  This option corresponds to the ‘-0’ option of xargs.
复制代码
回复 支持 反对

使用道具 举报

发表于 2007-1-18 11:38:37 | 显示全部楼层
find . -exec sh -c "if [[ -d \"{}\" ]]; then chmod 755 \"{}\"; else chmod 644 \"{}\"; fi " \;
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表