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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
04-27-2012, 02:36 AM
|
#1
|
Senior Member
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203
Rep:
|
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.
|
04-27-2012, 03:24 AM
|
#2
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 24,276
|
generate a list on the two drives, like ls -lR and compare the two results.
|
|
|
04-27-2012, 04:21 AM
|
#3
|
Senior Member
Registered: Mar 2012
Posts: 1,882
|
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.
|
04-27-2012, 07:38 AM
|
#4
|
Senior Member
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203
Original Poster
Rep:
|
Actually I have tried this one...
rsync -rvnc website/ laptop  rojects/website/
|
|
|
04-29-2012, 12:05 PM
|
#5
|
Senior Member
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
|
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
|
|
|
05-04-2012, 01:40 AM
|
#6
|
LQ Newbie
Registered: Aug 2009
Posts: 6
Rep:
|
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.
|
10-27-2017, 11:31 AM
|
#7
|
Member
Registered: Oct 2012
Location: Germany
Distribution: Xubuntu
Posts: 81
Rep: 
|
Quote:
Originally Posted by acalderon
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?
|
|
|
10-27-2017, 09:27 PM
|
#8
|
Member
Registered: May 2016
Posts: 222
Rep: 
|
Quote:
Originally Posted by tux111
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$
|
|
|
10-28-2017, 03:45 AM
|
#9
|
LQ Addict
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 24,276
|
another approach can be to use dupfinder....
|
|
|
10-28-2017, 04:20 AM
|
#10
|
LQ Guru
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Distribution: One main distro, & some smaller ones casually.
Posts: 5,875
Rep: 
|
You might also like to take a look at 'man cmp'.
|
|
|
All times are GMT -5. The time now is 07:36 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|