LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Compare two folders(recursively) for file names and file contents (https://www.linuxquestions.org/questions/linux-software-2/compare-two-folders-recursively-for-file-names-and-file-contents-942028/)

alaios 04-27-2012 02:36 AM

Compare two folders(recursively) for file names and file contents
 
Dear all,
I have received a hard disk from our technical department that has my data copied to a larger hard disk. I still also have the original disk with me and I was thinking if thereŽis any way to compare files and folders differences (not only file names as diff returns but also in their contents, so to make sure that the copy worked ok).

I

What do you suggest?

A

pan64 04-27-2012 03:24 AM

generate a list on the two drives, like ls -lR and compare the two results.

descendant_command 04-27-2012 04:21 AM

Maybe use rsync -n (dry run) to generate a list of different files, then feed the pairs to diff to compare contents.

Maybe diff has an option for this type of compare but I'm no guru with it.

alaios 04-27-2012 07:38 AM

Actually I have tried this one...

rsync -rvnc website/ laptop:projects/website/

sag47 04-29-2012 12:05 PM

Dry run with the update switch (-u) meaning it will only overwrite changed files.

Code:

rsync -ruptvn src/ dst/ > /tmp/output
Then you can edit the output file and delete the "speedup" output from the top and bottom so you just have the files to work with. Then you can run a diff...

Assuming you're using bash with the following,
Code:

sourcedir=src;destdir=dst;cat /tmp/output | while read file;do diff -rupN $sourcedir/$file $destdir/$file;done >> /tmp/differences;unset sourcedir destdir
Look at the /tmp/differences file to see the changes from diff.

SAM

acalderon 05-04-2012 01:40 AM

I was looking for...
 
A similar answer. I found this:

http://superuser.com/questions/16631...omparing-files

Basicaly, you run diff with two flags "qr" as follows:

diff -qr dir1 dir2

Make shure you substitute dir1 and dir2 with the directory paths that you want to compare. It will let you know if there are any diferences in directory structure and file contents.

Regards.

tux111 10-27-2017 11:31 AM

Quote:

Originally Posted by acalderon (Post 4669981)
A similar answer. I found this:

http://superuser.com/questions/16631...omparing-files

Basicaly, you run diff with two flags "qr" as follows:

diff -qr dir1 dir2

Make shure you substitute dir1 and dir2 with the directory paths that you want to compare. It will let you know if there are any diferences in directory structure and file contents.

Regards.

Does diff also consider contents of the files - not only file names?

nodir 10-27-2017 09:27 PM

Quote:

Originally Posted by tux111 (Post 5774446)
Does diff also consider contents of the files - not only file names?

Code:

user$ mkdir foo bar
user$ vi foo/testfile.txt
user$ cat foo/testfile.txt > ba
bar/    bar.txt  baz.txt 
user$ cat foo/testfile.txt > bar/testfile.txt
user$ diff foo/testfile.txt bar/testfile.txt
user$ echo "difference" >> bar/testfile.txt
user$ diff foo/testfile.txt bar/testfile.txt
1a2
> difference
user$


pan64 10-28-2017 03:45 AM

another approach can be to use dupfinder....

fatmac 10-28-2017 04:20 AM

You might also like to take a look at 'man cmp'.


All times are GMT -5. The time now is 08:15 PM.