Skip to content

Instantly share code, notes, and snippets.

@Roiseuxquentin
Last active September 7, 2018 14:56
Show Gist options
  • Save Roiseuxquentin/73a4b9f0c46953fb74aac485caf62173 to your computer and use it in GitHub Desktop.
Save Roiseuxquentin/73a4b9f0c46953fb74aac485caf62173 to your computer and use it in GitHub Desktop.
#!/bin/bash
#Find , compare and move duplicate files from different directory
# /!\` files' name need to be in block , like : "about_file-Title.pdf" , not "about file title.pdf"
clear
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color
#Change path (absolute) ,extension and destination path
pathA='./A/'
pathB='./B/'
fileType='pdf'
destinationPath='./'
#list files
ls -l $pathA | grep $fileType | awk '{ print $5 " " $9 }' > bufferA.ghost
ls -l $pathB | grep $fileType | awk '{ print $5 " " $9 }' > bufferB.ghost
totalLines=$(wc -l bufferB.ghost | cut -d ' ' -f1)
if ((totalLines != 0))
then
i=1
j=0
while [ $i != $[totalLines+1] ]
do
pdfA=$(sed -n "$i p" bufferA.ghost)
if grep -qe "$pdfA" bufferB.ghost
then
pdfA=$(sed -n "$i p" bufferA.ghost | awk '{ print $2 }')
echo -e "${RED}Duplicate $fileType${NC} find : $pdfA"
echo "move to $destinationPath"
mv $pathB$pdfA $destinationPath
#echo "deleted..."
#rm $pathB$pdfA
j=$[$j+1]
fi
i=$[$i+1]
done
if ((j > 0))
then
echo "__________________________________"
echo -e "${RED}$j ${NC}$fileType duplicate"
fi
else
echo " "
echo " "
echo -e "${GREEN} 0 ${NC}$fileType duplicate"
echo " "
echo " "
fi
rm buffer*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment