Reputation: 1155
Given 2 folder: /folder1 and /folder2 and each folder has some files and subfolders inside. I used following command to compare the file difference including sub folder :
diff -buf /folder1 /folder2
which found no difference in term of folder and file structural .
However, I found that there are some permission differences between these 2 folders' files. Is there simple way/command to compare the permission of each file under these 2 folders (including sub-folders) on Unix?
thanks,
Upvotes: 9
Views: 16886
Reputation: 24643
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 nameUpvotes: 12
Reputation: 1
find /dirx/ -lsa |awk '{ print $6" "$6" " $11 }'
2 times the owner
find /dirx/ -lsa |awk '{ print $6" "$6" " $11 }'
2 times the group
find /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
Upvotes: 0
Reputation: 4396
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.
Upvotes: 10