//View Tip #480
Similar Tips
» Manipulate Bash sockets using /dev/tcp
» vimdiff and svn
» Change file extension revisited
» .. revisited
» Counts files in the current directory and subdirectory

 

Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
A quick script to compare files from two directories (for example a backup and working directory).

#!/bin/bash

cr='*'
if [ -z $3 ]; then cr=$3; fi

for f in `find $1/$3 -type f | sed "s|$1/||"`
do
  printf "===!%-76s" "$f!" | tr ' !' '= '; echo
  diff $1/$f $2/$f | sed -e "s/^</$1: /" -e "s/^>/$2: /"
done


Usage: [script name] directory1 directory2 to check all files
[script name] directory1 directory2 *html to check files of type html.


View Comments »




Comments 

Add your comment

Comments are currently disabled
moogman
Man, that would be complete awesome if you couldn't do a recursive diff:

diff -r directory backup_directory
Posted 2009-01-13 12:47:33
OP
diff -r can't be limited by filetype though can it?
Posted 2009-01-13 14:44:06
You can exclude patterns from diff, which may accomplish the filetype filtering you mention:

-x PAT  --exclude=PAT  Exclude files that match PAT.
Posted 2009-01-13 15:14:11

Home Latest Browse Top 25 Random Hall Of Fame Contact Submit