#!/bin/bash if [ "$1" = ":PREFIX:" ]; then prefix="$2" self="$0" shift 2 else prefix="" self=`dirname "$0"` self=`cd "$self" ; pwd`/`basename "$0"` fi if [ "$#" -lt 1 ]; then echo "Usage: $0 [file...]" exit 1 elif [ "$#" -eq 1 ]; then other="$1" set "." else other="$1" shift 1 fi if [ -d "$other" -a "$prefix" = "" ]; then other="`( cd \"$other\" ; pwd )`" fi if [ -d "$other" ]; then if [ "`pwd`" = "$other" ]; then echo "Cannot compare this directory with itself!" exit 1 fi else echo "Directory $other does not exist!" exit 1 fi # Compare regular files for x in "$@"; do if [ -f "$x" ]; then echo -n "$prefix$x... " if [ -f "$other/$x" ]; then if diff -q -- "$x" "$other/$x" > /dev/null; then echo "equal -- removing!" rm -- "$x" else echo "different" fi elif [ -e "$other/$x" ]; then echo "other file is not regular" else echo "other missing" fi fi done # Descend into subdirs glob_dot_filenames=1 dotglob=1 shopt -s dotglob for x in "$@"; do if [ -d "$x" ]; then if [ -L "$x" ]; then echo "skipping symblic link: $x" else if [ "$prefix" != "" ]; then if [ "$x" = "." -o "$x" = ".." ]; then continue fi fi ( cd "$x" ; "$self" :PREFIX: "$prefix$x/" "$other/$x" * ) if [ "$x" != "." ]; then rmdir -- "$x" > /dev/null 2>&1 fi fi fi done