The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
to compare total directory structure and get sizes of all f on two different servers mannam srinivas Shell Programming and Scripting 3 04-07-2008 04:21 AM
Need Script to check file exist and compare rbknisely UNIX for Dummies Questions & Answers 1 01-16-2008 01:08 AM
How to compare the dates in shell script vaji Shell Programming and Scripting 9 02-28-2007 12:34 AM
shell script cant recognize if else compare jaseloh Shell Programming and Scripting 6 12-06-2005 11:34 PM
script to compare files pulse2india Shell Programming and Scripting 0 10-19-2005 04:32 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-08-2007
jwilliams108 jwilliams108 is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 2
Directory compare script

Hello,

I am looking for a script, or pointer to an approach to creating a script, that will compare two versions of a codebase and output a third directory structure containing only the files that differ between the two. I use diff quite often, but it will only create patch files (AFAIK). Does anyone have any suggestions?

Thanks,
Jim
  #2 (permalink)  
Old 02-08-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,643
You can use md5 or cksum to get a checksum for each file. Assuming you have identical filename, each directory has the same number of files in both directories and the directories are:
/path/to/source/dir1 and /path/to/source/dir2
try something like this (untested)

Code:
#!/bin/ksh
cd /path/to/source
mkdir ./both/dir1
mkdir ./both/dir2
cd .dir1
find . -type f | \
while read file1
do
     cksum $file1 | read ck1 dummy dummy1
     file2=../dir2/"$file"
     cksum $file2 | read ck2 dummy dummy1
     if [[ "$ck1" != "$ck2" ]] ; then
        cp $file1 ../both/dir1/$file1
        $( cd /path/to/source/dir2 ; cp $file1 ../both/dir2/$file1)
     fi
done
  #3 (permalink)  
Old 02-08-2007
jwilliams108 jwilliams108 is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 2
Hi Jim,

Thanks alot! I didn't even think of checksumming... I'll give this a try. However, while the filenames will be identical, there may be differences in the number of files/directories between the two sources.

Jim
  #4 (permalink)  
Old 02-08-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,643
You'll have to deal with oddballs your own way. If dir1 had file13.c and dir2 did not have have file13.c, I would say that's a discrepency, so file13.c gets moved into the discrepency pile.

If there are different trees involved you will have to find a way to have both sets of trees under /both/dir1 & /both/dir2
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate 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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 07:28 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0