Last active
June 30, 2019 18:43
-
-
Save keyro90/710174cc19a921bfdff19e90d4606250 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
if [[ $# != 1 ]] ; then | |
echo 'Il comando chiede un argomento, la cartella dove scansionare' | |
exit 0 | |
fi | |
RED='\033[1;31m' | |
GREEN='\033[0;32m' | |
YELLOW='\033[1;33m' | |
NC='\033[0m' | |
echo | |
echo -e "${GREEN}--> Inizia la scansione "$(date '+%d/%m/%Y %H:%M:%S')${NC} | |
echo | |
SUB_SPACE="____" | |
# find all files inside folder passing has argument, only with basename. | |
LISTFILES=$(find $1 -type f -print0 | xargs -0 -n 1 basename | tr " " "${SUB_SPACE}") | |
files_list=() | |
COUNT=0 | |
echo -e "${GREEN}--> In questa cartella ci sono $(echo $LISTFILES | wc -w) file"${NC} | |
echo -e "${GREEN}--> Sto cercando i file duplicati, potrebbe volerci del tempo"${NC} | |
echo | |
for f in $LISTFILES; do | |
FOUND=0 | |
if [ ${#files_list[@]} -gt 0 ]; then | |
# to lower, because i need to compare insensitive string | |
F1=$(printf "$f" | tr '[:upper:]' '[:lower:]') | |
for el in ${files_list[*]}; do | |
F2=$(printf "$el" | tr '[:upper:]' '[:lower:]') | |
if [ "$F1" == "$F2" ]; then | |
FOUND=1 | |
break | |
fi | |
done | |
fi | |
if [ "$FOUND" -eq "1" ]; then | |
continue | |
fi | |
files_list[$COUNT]=${f} | |
COUNT=$((COUNT+1)) | |
done | |
echo -e "${GREEN}--> Costruisco il report" | |
echo | |
for el in ${files_list[*]}; do | |
NORM_EL=$(echo "$el" | tr "${SUB_SPACE}" " ") | |
RES=$(find $1 -iname "$NORM_EL" -type f) | |
N_RES=$(echo $RES | wc -w) | |
if [ "$N_RES" -gt 1 ]; then | |
printf "${RED}File duplicati per ${YELLOW}${el}${NC} : \n" | |
printf "${RES}\n" | |
echo | |
fi | |
done | |
echo -e "${GREEN}--> Script Terminato "$(date '+%d/%m/%Y %H:%M:%S')${NC} | |
echo | |
echo | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment