Makistos
10/28/2013 - 8:01 AM

This script will remove files in the directory given as first parameter that have a similarly named file in the directory named as the secon

This script will remove files in the directory given as first parameter that have a similarly named file in the directory named as the second parameter. #duplicates #file-handling #bash

#/bin/bash

DIR_1=$1;
DIR_2=$2;

for i in `find $DIR_1 -name "*"` ; do
  if [ ! -d $i ] ; then
    name=$(basename $i);
    files=`find $DIR_2 -iname $name | egrep -v "$DIR_1"` ;
    if [ "$files" != "" ] ; then
      rm $i;
    fi
  fi
done