Jon*_*han 4 permissions find files
假设我有一个文件夹,其中包含其他文件和文件夹,我想递归地找出哪些子文件和子文件夹具有非默认权限(即,不是 644 或 755)。
可以使用哪个命令来做到这一点?该命令应输出相关文件和文件夹及其权限的列表。
您只需使用以下命令即可完成整个任务find
:
$ find . -type f ! \( -perm 755 -o -perm 644 \) -printf "%m\t%p\n"
Run Code Online (Sandbox Code Playgroud)
进行所有权限排列 (000-777)。
$ touch {0..7}{0..7}{0..7}
$ for i in {0..7}{0..7}{0..7}; do chmod $i $i;done
$ find . -type f | wc -l
512
Run Code Online (Sandbox Code Playgroud)
我们的find
命令找到的文件列表示例:
$ find . -type f ! \( -perm 755 -o -perm 644 \) -printf "%m\t%p\n"| head -10
734 ./734
376 ./376
555 ./555
663 ./663
256 ./256
336 ./336
2 ./002
152 ./152
527 ./527
416 ./416
Run Code Online (Sandbox Code Playgroud)
如果我们运行我们的find
命令,我们可以确认它有效:
$ find . -type f ! \( -perm 755 -o -perm 644 \) -printf "%m\t%p\n" | grep 755
$ find . -type f ! \( -perm 755 -o -perm 644 \) -printf "%m\t%p\n" | grep 644
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4326 次 |
最近记录: |