LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 07-04-2006, 05:45 AM   #1
ursusman
LQ Newbie
 
Registered: Jan 2005
Posts: 8

Rep: Reputation: 0
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.
 
Old 07-04-2006, 05:48 AM   #2
chief_officer
Member
 
Registered: Mar 2006
Location: Istanbul, TR
Distribution: Red Hat, CentOS, Ubuntu
Posts: 181

Rep: Reputation: 30
Try dircmp and diff commands [don't forget to check out their man pages].

Regards
 
Old 07-04-2006, 05:52 AM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
"man diff", look for recursion flag, look for "minimal output" flag: end up with "diff --brief -r dir1 dir2".
(FCOL: experiment will ya! ;-p )
 
Old 07-04-2006, 05:59 AM   #4
ursusman
LQ Newbie
 
Registered: Jan 2005
Posts: 8

Original Poster
Rep: Reputation: 0
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.
 
Old 07-04-2006, 06:05 AM   #5
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
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.
 
Old 07-04-2006, 06:56 AM   #6
ursusman
LQ Newbie
 
Registered: Jan 2005
Posts: 8

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by jschiwal
You could use sed to convert the format.
It is exactly what I started doing. Thanks!
 
  


Reply



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
Comparing \ in java MRMadhav Programming 10 02-27-2006 03:22 AM
Searching multiple directories and sub directories for a file jeep99899 Linux - Newbie 2 10-13-2005 12:23 PM
comparing drives warinthepocket Linux - General 7 09-23-2005 05:56 PM
Comparing 2 Files xianzai Programming 2 05-23-2004 11:50 AM
check for matching files when comparing directories WarriorWarren Linux - General 3 05-07-2003 01:40 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:17 PM.

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