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,
The file comparison command helps us to compare the files and find the similarities and differences between these files. The different file comparison commands used in Unix are cmp, comm, diff, dircmp, and uniq. Unix Video #8: Different ways of comparing two files in Unix. #1) cmp: This command is used to compare two files character by character.
Unix Permissions: File Permissions with Examples. Access to a file has three levels: Read permission – If authorized, the user can read the contents of the file. Write permission – If authorized, the user can modify the file.
confirming if files in two directories are the same – a typical task when comparing your actual data against a backup copy. When something goes wrong, this is one of the first things you do to make sure all the important files are not only present, but are actually the same as they have been when you took the last backup copy
The easiest way to get started is to simply invoke diff command and specify two directories as command line parameters. Here’s what you will probably see: ubuntu$ diff /tmp/dir1 /tmp/dir2 Common subdirectories: /tmp/dir1/dir11 and /tmp/dir2/dir11 diff /tmp/dir1/file1 /tmp/dir2/file11 Only in /tmp/dir1: file2 Only in /tmp/dir2: file3
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 nameIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With