Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare 2 folders' permission on Unix?

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,

like image 968
Bill Lin Avatar asked Jul 03 '14 10:07

Bill Lin


People also ask

How to compare two files in Unix?

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.

What are Unix file permissions?

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.

How do I confirm if files in two directories are the same?

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

How do I diff files between two directories in Ubuntu?

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


1 Answers

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
like image 130
yukondude Avatar answered Sep 21 '22 04:09

yukondude