Thursday, January 31, 2008

Compare Directory Contents on Linux computer

#/bin/bash

DIR_1=$1
DIR_2=$2

#check dir diffs

ls -1 $DIR_1 >/tmp/diff.1
ls -1 $DIR_2 >/tmp/diff.2


echo "Check Dir differences:"
diff /tmp/diff.1 /tmp/diff.2 && echo "Dir's have the same files"

#check files differences

echo "check files differences:"
for file in `cat /tmp/diff.1 /tmp/diff.2|uniq`; do
diff $DIR_1/$file $DIR_2/$file 2>/dev/null
done

rm /tmp/diff.1 /tmp/diff.2
posted by Stephen Reese at

4 Comments:

OpenID vtmckoy said...

Missing $ sign; should be:

DIR_1=$1
DIR_2=$2

10/25/2008 09:11:00 PM  
Blogger Stephen Reese said...

Hey vtmckoy,

Thanks for the heads up on that...

10/26/2008 01:12:00 AM  
Blogger Fer said...

Thanks for the script. As vtmckoy posted, you should modify the two definitions, moving the $ sign to the other side of the equality. You might want to perform the modification in the post.

11/02/2008 02:59:00 AM  
Blogger Stephen Reese said...

fer,

Hey thanks for the correction. I have implemented the changes.

11/02/2008 04:39:00 PM  

Post a Comment

<< Home