How to compare 2 folders' permission on Unix? How to compare 2 folders' permission on Unix? unix unix

How to compare 2 folders' permission on Unix?


One way to compare permissions on your two directories is to capture the output of ls -al to a file for each directory and diff those.

Say you have two directories called a and b.

cd als -alrt > ../a.listcd ../bls -alrt > ../b.listcd ..diff a.list b.list

If you find that this gives you too much noise due to file sizes and datestamps you can use awk to filter out some of the columns returned by ls e.g.:

ls -al | awk {'printf "%s %s %s %s %s %s\n", $1,$2,$3,$4,$5,$9 '}

Or if you are lucky you might be able to remove the timestamp using:

ls -lh --time-style=+

Either way, just capture the results to two files as described above and use diff or sdiff to compare the results.


If you have the tree command installed, it can do the job very simply using a similar procedure to the one that John C suggested:

cd atree -dfpiug > ../a.listcd ../btree -dfpiug > ../b.listcd ..diff a.list b.list

Or, you can just do this on one line:

diff <(cd a; tree -dfpiug) <(cd b; tree -dfpiug)

The options given to tree are as follows:

  • -d only scans directories (omit to compare files as well)
  • -f displays the full path
  • -p displays permissions (e.g., [drwxrwsr-x])
  • -i removes tree's normal hierarchical indent
  • -u displays the owner's username
  • -g displays the group name


find /dirx/ -lsa |awk '{ print $6" "$6" " $11 }' 2 times the ownerfind /dirx/ -lsa |awk '{ print $6" "$6" " $11 }' 2 times the groupfind /dirx/ -lsa |awk '{ print $5" "$6" " $11 }' owner and group

Then you can redirect to a file for diff or just investigate piping to less ( or more ).You can also pipe to grep and grep or "ungrep" (grep -v) to narrow the results.Diff is not very useful if the dir contents are not the same