Bash脚本获取两个目录中文件的权限差异
如何在 Linux 上编写 bash 脚本来确定两个目录中的哪些文件具有不同的权限?
例如,我有两个目录:
fold1
有两个文件:
1- file1 (-rw-rw-r--)
2- file2 (-rw-rw-r--)
fold2
有具有不同权限的同名文件:
1- file1 (-rwxrwxr-x)
2- file2 (-rw-rw-r--)
我需要一个脚本来输出具有不同权限的文件名, 所以脚本只会打印 file1
我目前正在通过显示文件来手动检查权限:
for i in `find .`; do ls -l $i ls -l ../file2/$i; done
How can I write a bash
script on Linux to determine which files in two directories have different permissions?
For example, I have two directories:
fold1
having two files:
1- file1 (-rw-rw-r--)
2- file2 (-rw-rw-r--)
fold2
having same-name files with different permissions:
1- file1 (-rwxrwxr-x)
2- file2 (-rw-rw-r--)
I need a script to output the file names that have different permissions,
so the script will print only file1
I am currently checking the permissions manually by displaying the files with:
for i in `find .`; do ls -l $i ls -l ../file2/$i; done
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解析
find .
输出:for i in $(find .)
会给您带来任何带有空格、换行符或其他完全正常字符的文件名的麻烦:使用以下方式 可能也因所有者或团体而异,我认为您也应该包括这些。如果您需要包含 SELinux 安全标签,
stat(1)
程序也可以通过%C
指令轻松实现:(为
echo
命令...)示例:
Parsing
find .
output with:for i in $(find .)
is going to give you trouble for any filenames with spaces, newlines, or other perfectly normal characters:Since permissions can also differ by owner or by group, I think you should include those as well. If you need to include the SELinux security label, the
stat(1)
program makes that easy to get as well via the%C
directive:(Do whatever you want for the
echo
command...)Example: