//View Tip #480
Similar Tips
» Fix the previous command
» Overwrite a file with zeroes
» Keeping your Home Directory Organized
» Truncated $PWD in the command prompt
» Splitting arguments with read


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).


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

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

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

View Comments »


Add your comment

Comments are currently disabled
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
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