Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
| 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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
07-04-2006, 05:45 AM
|
#1
|
|
LQ Newbie
Registered: Jan 2005
Posts: 8
Rep:
|
Comparing directories
Hi everyone,
I have to compare two directories in order to indentify which files are changed, which files were added and which ones were deleted. I would like to see output something like this when comparing two directories dir1 and dir2:
dir1/file1 - changed
dir1/file2 - missing
dir1/file3 - added
Is there an utility in Linux that can easily do this? I expect diff should know how to do this, but I cannot figure out how to tell diff what I want. Could anyone help me?
Thank you in advance.
|
|
|
|
07-04-2006, 05:48 AM
|
#2
|
|
Member
Registered: Mar 2006
Location: Istanbul, TR
Distribution: Ubuntu 9.04
Posts: 177
Rep:
|
Try dircmp and diff commands [don't forget to check out their man pages].
Regards
|
|
|
|
07-04-2006, 05:52 AM
|
#3
|
|
Moderator
Registered: May 2001
Posts: 24,779
|
"man diff", look for recursion flag, look for "minimal output" flag: end up with "diff --brief -r dir1 dir2".
(FCOL: experiment will ya! ;-p )
|
|
|
|
07-04-2006, 05:59 AM
|
#4
|
|
LQ Newbie
Registered: Jan 2005
Posts: 8
Original Poster
Rep:
|
Thanks for replies.
What I was doing up to the moment is:
diff -qr dir1 dir2
Because I need only list of the files that changed/missed/added, I don't like output like:
File dir1/file1 and dir2/file2 differ
Only in dir2/: file2
Only in dir1/: file3
I want to see something simpler and I though that there could be some option which I couldn't figure out:
! dir1/file1
- dir1/file2
+ dir1/file3
I think I just have to write simple script to reformat output the way I need it.
Last edited by ursusman; 07-04-2006 at 06:02 AM.
|
|
|
|
07-04-2006, 06:05 AM
|
#5
|
|
Moderator
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733
|
You could use sed to convert the format. For example
sed '/differ/s/Files \(.*\) and .* differ/! \1/' to convert from
Files dira/b and dirb/b differ
to
! dira/b
----
diff -qr dirb dira | sed -e '/differ/s/Files \(.*\) and .* differ/! \1/' \
> -e '/Only/s/Only in \(.*\): \(.*\)/+ \1\/\2/'
! dirb/b
! dirb/e
+ dira/g
+ dirb/h
Last edited by jschiwal; 07-04-2006 at 06:18 AM.
|
|
|
|
07-04-2006, 06:56 AM
|
#6
|
|
LQ Newbie
Registered: Jan 2005
Posts: 8
Original Poster
Rep:
|
Quote:
|
Originally Posted by jschiwal
You could use sed to convert the format.
|
It is exactly what I started doing. Thanks!
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 06:14 AM.
|
|
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
|
|