lonestar21
lonestar21

Reputation: 1193

find files unique to different paths BASH

I have a suspicion that a few years ago someone accidentally copied a folder structure from /home/data to /home/something/data. Since then /home/data has had many updates and changes. What is the easiest way to check if there are any files in /home/something/data unique (by name and location) to that location, to help me confirm if everything in there was a copy from /home/data?

Upvotes: 2

Views: 438

Answers (3)

Mark Setchell
Mark Setchell

Reputation: 207445

You may or may not like this approach, it can take a while to scan all files but I generally have a good feeling when I do it.

Go to the top of each directory structure and run a find and get the md5 checksums of each and every file - your switches may vary as I am on OSX

cd /home/data
find . -type f -exec md5 -r {} + > /tmp/a

cd /home/something/data
find . -type f -exec md5 -r {} + > /tmp/b

When they are finished, run the output files through sort and uniq -u to tell you the lines that only appear once (they should all appear twice if the files are the same in both directories):

sort < /tmp/[ab] | uniq -u

Upvotes: 2

chepner
chepner

Reputation: 531065

Use rsync in dry-run mode to see if copying /home/something/data into /home/data would actually copy any data.

 rsync -r --dry-run /home/something/data /home/data

If a file under /home/something/data is identical to a file under /home/data, it would not be copied, and rsync --dry-run will not report it.

Upvotes: 2

salezica
salezica

Reputation: 76909

Using diff -r dir1 dir2, you can recursively scan directories for differences in structure and content. Additional flags can tweak the output and behavior to your liking.

Upvotes: 2

Related Questions