Help with finding dups

Help with finding dups

Post by Tony » Sat, 12 Feb 2000 04:00:00



Would any of you Unix shell scripting gurus happen to have a small
script on have that would ...

Ask for at least two directories to search for duplicates in
create a dump of all dups it finds to a file
prompt me (Y/N) to do a diff on the two files to make sure it is a dup

Thanks muchly!

Tony!

 
 
 

Help with finding dups

Post by Eike Rietze » Sat, 12 Feb 2000 04:00:00


I hope this helps. It may not be really good but it should do the job.
If you only want the files that show no difference in the logfile
uncomment the line indicated below and remove the first echo >>
${LOGFILE}.

Eike

#!/bin/ksh
# syntax: double.ksh directory1 directory2
file_to_write_names_of_files_to

DIR1=$1
DIR2=$2
LOGFILE=$3

# if the logfile exists remove it
if [ -f ${LOGFILE} ] ; then rm ${LOGFILE} ; fi

# list contents of dir1 in array listing1
set -A LISTING1 `ls ${DIR1}`

# set FILE to all the different contents in the array (files in dir1)
for FILE in ${LISTING1[*]}
# if the file exists in the second directory
  do if [ -f ${DIR2}/${FILE} ]
# write the filename to logfile
# remove the echo ${FILE} >> ${LOGFILE} if you want only... and use the
line indicated below instead
    then echo ${FILE} >> ${LOGFILE}
# do a diff or not?
    printf "diff ${DIR1}/${FILE} ${DIR2}/${FILE}? "
# read the answer
    read DIFFORNOT
# if y was entered do the diff
    if [ ${DIFFORNOT} = 'y' ]
      then diff ${DIR1}/${FILE} ${DIR2}/${FILE}
# check the exit status of the diff
      if [[ $? = 0 ]]
        then echo "Files are identical."
# use the following line if you want the not differint files in ythe
logfile only
#        echo ${FILE} >> ${LOGFILE}
      else
        echo "Files differ."
      fi
    fi
  fi
done


> Would any of you Unix shell scripting gurus happen to have a small
> script on have that would ...

> Ask for at least two directories to search for duplicates in
> create a dump of all dups it finds to a file
> prompt me (Y/N) to do a diff on the two files to make sure it is a dup

> Thanks muchly!

> Tony!

--
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

Eike Rietzel
Gesellschaft fuer Schwerionenforschung
Biophysik
Planckstr. 1
64291 Darmstadt
fon: +49-6159-71-2156
fax: +49-6159-71-2106
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

 
 
 

Help with finding dups

Post by Ken Pizzi » Thu, 17 Feb 2000 04:00:00



># if the logfile exists remove it
>if [ -f ${LOGFILE} ] ; then rm ${LOGFILE} ; fi

I wonder if this is really a desirable thing to do, but
assuming that it is: there is no need to check that a file
exists before unconditionally removing it; just:
  rm -f "${LOGFILE}"
and be done with it.

                --Ken Pizzini