Directory compare script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Directory compare script
# 1  
Old 02-08-2007
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  
Old 02-08-2007
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  
Old 02-08-2007
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  
Old 02-08-2007
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare directory dates

hi, I need to know if a specific directory exists in a folder named after the date of yesterday (02/06/2015) The problem is simple but not how to do it. :confused:i= date -d "yesterday" '%Y-%m-%d' <- the format of directory is 2015-06-02 if in /var/logroot/index exist directory whit... (4 Replies)
Discussion started by: tmeto
4 Replies

2. Shell Programming and Scripting

Compare file names on directory

Dears, Would you please help on following bash script: I want to get the most recent file named alfaYYYYMMDD.gz in one directory: for example: in directory /tmp/ ls -ltr alfa20130715.gz holding.gz alfa20130705.gz sart.txt merge.txt.gz alfa20130802.gz my result shoud be... (1 Reply)
Discussion started by: maxsub
1 Replies

3. Shell Programming and Scripting

Compare new version of two directory

How to compare new version exist of two path directory. for e.g., path1 - /user/path/test/ path2 - /user/path/score/ If its exist new version then copy that new version into the first path directroy. How will do this. (3 Replies)
Discussion started by: roy1912
3 Replies

4. Shell Programming and Scripting

Script to compare substrings of multiple filenames and move to different directory

Hi there, I am having trouble with a script I have written, which is designed to search through a directory for a header and payload file, retrieve a string from both filenames, compare this string and if it matches make a backup of the two files then move them to a different directory for... (1 Reply)
Discussion started by: alcurry
1 Replies

5. Shell Programming and Scripting

Compare files in a directory

Hi friends, can anyone help me comparing files in a directory. I have files f1, f2, f3, f4, f5, f6, f7, f8 in a directory each created on a daily basis as f1 on day1, f2 on day2, f3 on day3, f4 on day4, f5 on day5, f6 on day6, f7 on day7, f8 on day8. I need ignore the latest two files (here f7 and... (5 Replies)
Discussion started by: nmattam
5 Replies

6. Solaris

directory compare in two different servers

How can we get the directory tree along with the size in two different servers and find the difference between the list..?? Eg, Server1 dirTree1 -size Server 2 dirTree2 -size how can we find the directory tree with its size, and find the difference, where the servers are different... (1 Reply)
Discussion started by: vikram3.r
1 Replies

7. Shell Programming and Scripting

How to compare a directory from both remote server

Hi ALL. Wanted to ask on how to compare a directory from both remote server. Example: server0>$ diff -r men@server1:/main/dir1 men@server2:/main/dir1 Many thanks in advance. (4 Replies)
Discussion started by: BCJapan
4 Replies

8. Shell Programming and Scripting

Compare all files in a directory to a threshold value

Hi guys, I have the following, and would like to enhance it be be able to run it in the hard coded directory and compare each file in the directory with the expectedSizeHow would I go about doing this? Thanks, Bloke #!/bin/sh ] || { echo "Usage: watchSizes 400"; exit 0 ; } #Hammer: How... (1 Reply)
Discussion started by: Bloke
1 Replies

9. Shell Programming and Scripting

to write a script to compare the file size in the current directory and previous dir

hi, i am new to this site. i want to write a script to compare the file size of the files in the current dir with the files in the previous directory. the files name will be same, but the filename format will be as xyzddddyymm.txt. the files will arrive with the month end date(i want to... (5 Replies)
Discussion started by: tweety
5 Replies

10. Shell Programming and Scripting

How to compare size of two file which is in one directory

I have two file in a Directory.I want a script which will compare the Size of Two file. Can Anyone Help me on this: linasplg11:/opt/dataout/kk/linasplg11 # cat size -rwxrwxrwx 1 root root 16658 Jan 8 13:58 lina_IP_SIP_1231325621210.xml -rwxr-xr-x 1 root root 16672 Jan 8 14:30... (1 Reply)
Discussion started by: Aditya.Gurgaon
1 Replies
Login or Register to Ask a Question