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