Sunday, March 31, 2019

Linux: compare two directories and find out the unique files


Supposed there are two similar directories holding a mass of files. Most of the files in the two directories are duplicate, but each directories have some files unique to themselves. If you want to find out the unique files from each directory, you can:

1. List all the files in each directory. Send the output to two separate files.
$ cd /path/to/directory1
$ find . -type f | sort > /tmp/files1
$ cd /path/to/directory2
$ find . -type f | sort > /tmp/files2

2. Find the files unique in directory1
comm -23 /tmp/files1 /tmp/files2

3. Find the files unique in directory2
comm -13 /tmp/files1 /tmp/files2

4. Find the files in both directories
comm -12 /tmp/files1 /tmp/files2

No comments:

 
Get This <