LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-27-2012, 02:36 AM   #1
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

Rep: Reputation: 45
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
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 04-27-2012, 03:24 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,687

Rep: Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274
generate a list on the two drives, like ls -lR and compare the two results.
 
Old 04-27-2012, 04:21 AM   #3
descendant_command
Senior Member
 
Registered: Mar 2012
Posts: 1,876

Rep: Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643Reputation: 643
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.
 
2 members found this post helpful.
Old 04-27-2012, 07:38 AM   #4
alaios
Senior Member
 
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

Original Poster
Rep: Reputation: 45
Actually I have tried this one...

rsync -rvnc website/ laptoprojects/website/
 
Old 04-29-2012, 12:05 PM   #5
sag47
Senior Member
 
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
Blog Entries: 36

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
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
 
Old 05-04-2012, 01:40 AM   #6
acalderon
LQ Newbie
 
Registered: Aug 2009
Posts: 6

Rep: Reputation: 1
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.
 
1 members found this post helpful.
Old 10-27-2017, 11:31 AM   #7
tux111
Member
 
Registered: Oct 2012
Location: Germany
Distribution: Xubuntu
Posts: 81

Rep: Reputation: Disabled
Quote:
Originally Posted by acalderon View Post
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?
 
Old 10-27-2017, 09:27 PM   #8
nodir
Member
 
Registered: May 2016
Posts: 222

Rep: Reputation: Disabled
Quote:
Originally Posted by tux111 View Post
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$
 
Old 10-28-2017, 03:45 AM   #9
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,687

Rep: Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274Reputation: 7274
another approach can be to use dupfinder....
 
Old 10-28-2017, 04:20 AM   #10
fatmac
LQ Guru
 
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Distribution: Mainly Devuan with some Tiny Core, Fatdog, Haiku, & BSD thrown in.
Posts: 5,442

Rep: Reputation: Disabled
You might also like to take a look at 'man cmp'.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Inquiry:How to compare the contents of two folders? hadimotamedi Linux - Newbie 7 12-02-2009 05:26 AM
[SOLVED] Script: Trim all file names recursively Flukester Linux - Server 9 10-28-2009 06:37 AM
Script to Compare Folder Structures and File Contents rajaniyer123 Solaris / OpenSolaris 2 11-11-2008 01:31 PM
my cd contents file names not displaying morethan 8 digits. AMajeed AIX 5 08-08-2007 09:56 AM
How to compare two folders contents? rvoigt Linux - Newbie 6 01-07-2005 12:35 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration