LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Comparing directories (https://www.linuxquestions.org/questions/linux-newbie-8/comparing-directories-460847/)

ursusman 07-04-2006 06:45 AM

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.

chief_officer 07-04-2006 06:48 AM

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

Regards

unSpawn 07-04-2006 06:52 AM

"man diff", look for recursion flag, look for "minimal output" flag: end up with "diff --brief -r dir1 dir2".
(FCOL: experiment will ya! ;-p )

ursusman 07-04-2006 06:59 AM

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.

jschiwal 07-04-2006 07:05 AM

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

ursusman 07-04-2006 07:56 AM

Quote:

Originally Posted by jschiwal
You could use sed to convert the format.

It is exactly what I started doing. Thanks!


All times are GMT -5. The time now is 10:29 AM.