Hi Tony,
I'm always twitchy just running commands or scripts without building them up and testing them gradually, and without a final sanity check of seeing what it's going to do before I run it.
This is especially the case in a Production environment and where the rm command is used! :)
This might seem long winded but this is what I'd do:
1) create script rm_dups.ksh as below
2) run the script and check it's output,
3) once satisfied it's going to work as intended run it's output via
$ rm_dups.ksh |ksh -x
...not forgetting to sent the output to a logfile of course :)
Contents of script rm_dups.ksh:
#!/usr/bin/ksh
#-- Check that at least 1 parameter has been passed
if [[ $# -eq 0 ]]; then
echo "# ERROR: no directories passed"
exit 10
fi
#-- Loop for each directory passed
for DIR in $@
do
echo
ec---------"
date +"# %Y/%m/%d %H:%M:%S Removing duplicates from ${DIR} ..."
#-- Check that directory $DIR exists and is a directory
if [[ ! -d ${DIR} ]]; then
echo "# WARNING: directory ${DIR} does not exist"
else
#-- Loop through each pdf file in directory $DIR
for FILE in `find ${DIR} -type f -name "*pdf"`
do
echo
date +"# %Y/%m/%d %H:%M:%S Processing file ${FILE} ..."
#-- List file for reference
ls -l ${FILE} |sed -e 's/^/# /'
FILE2RM=`echo ${FILE} |sed -e 's/.pdf$/.ps/'`
if [[ -f ${FILE2RM} ]]; then
ls -l ${FILE2RM} |sed -e 's/^/# /'
echo "# File ${FILE2RM} exists"
echo "rm ${FILE2RM}"
else
echo "# File ${FILE2RM} does not exist"
fi
done # FILE
fi
done # DIR
exit 0