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
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%Cdirective:(Do whatever you want for the
echocommand…)Example: