#!/bin/sh # treeprune - remove files from current tree when they match a target tree # # Copyright Tony Aiuto 1990-1992 # # 11/29/90 tony - removed redundent first are, add -e option # - better error checking # 01/07/91 tony - add -x flag to only check executables, -h flag for Harsh mode # 10/04/92 tony - remove recol references # 02/24/98 tony - add pre-remove symbolic links and post-remove directories # # Send comments and money to tony@aiu.to # Edit=0 exeOnly=0 harsh=0 EDITOR=${EDITOR:-vi} while [ -n "$1" ] ; do case $1 in -e ) Edit=1 shift ;; -x ) exeOnly=1 shift ;; -h ) harsh=1 shift ;; -* ) echo "treeprune: unknown option $1" exit 1 ;; * ) break ;; esac done if [ $# -ne 1 ] ; then echo 'usage: treeprune [-e] [-h] [-x] TargetDirectory -e allow edit of file list before pruning -h harsh mode: existance of matching name causes delete -x only check executable files (as determined by file command) ' exit 1 fi to=$1 if [ ! -d $to ] ; then echo $to is not a directory exit 2 fi curPath=`pwd` toPath=`(cd $to ; pwd)` if [ $curPath = $toPath ] ; then echo "You can't prune against your current directory" exit 3 fi echo Pruning files from $curPath against $toPath trap "rm -f /tmp/$$ ; exit 0" 0 1 2 3 4 15 # first remove symbolic links find . -type l -exec /bin/rm \{} \; # now get the list of files find . -type f -print >/tmp/$$ if [ $exeOnly -ne 0 ] ; then echo Executables only. xargs file /tmp/$$.1 mv /tmp/$$.1 /tmp/$$ fi if [ $Edit -ne 0 ] ; then $EDITOR /tmp/$$ fi if [ $harsh -ne 0 ] ; then echo Pruning harshly, mere existance is enough for the prune while read i do if [ -r $to/$i ] ; then rm -f $i fi done /dev/null) ; then rm -f $i fi else basei=`expr $i : '\(.*\).Z$'` if [ -f $to/$basei ] ; then if (zcat $i | cmp - $to/$basei >/dev/null); then rm -f $i fi fi fi ;; *.gz ) if [ -f $to/$i ] ; then if (cmp $i $to/$i >/dev/null) ; then rm -f $i fi else basei=`expr $i : '\(.*\).gz$'` if [ -f $to/$basei ] ; then if (gzip -d <$i | cmp - $to/$basei >/dev/null); then rm -f $i fi fi fi ;; * ) if (cmp $i $to/$i >/dev/null) ; then rm -f $i fi ;; esac done