![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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 |
|
||||
|
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
|
|
||||
|
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 | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|