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 a
ls -alrt > ../a.list
cd ../b
ls -alrt > ../b.list
cd ..
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 a
tree -dfpiug > ../a.list
cd ../b
tree -dfpiug > ../b.list
cd ..
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