Skip to content

Instantly share code, notes, and snippets.

@rubenwardy
Created July 21, 2017 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rubenwardy/bcaf3ac30908f6de8c67e10d7ebb0629 to your computer and use it in GitHub Desktop.
Save rubenwardy/bcaf3ac30908f6de8c67e10d7ebb0629 to your computer and use it in GitHub Desktop.
find . -type f -print > list.txt
# Initiate progress counter
NUM=$(grep -E "/[0-9]-[0-9]+ [^/]*$" list.txt | wc -l)
IDX=1
# Iterate through each bad name
grep -E "/[0-9]-[0-9]+ [^/]*$" list.txt | while read x; do
# Progress bar
>&2 echo -en "\n[$IDX / $NUM] "
IDX=$((IDX+1))
>&2 echo "$x:";
# Get name of good file
FILE=$(sed -E 's/[0-9]-([0-9]+) ([^/]+)$/\1 - \2/g' <<< $x)
# Debug logging
echo "For $x"
echo " - Checking for $FILE"
# Check that good file exists
if [ -f "$FILE" ]; then
echo " - Found"
# Move bad file
ID=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 13)
FN=$(sed -e 's/[^A-Za-z0-9._-]/_/g' <<< $x)
mv "$x" "/home/ruben/mscbk/$FN-$ID"
# Provide mapping
echo " - safe name /home/ruben/mscbk/$FN-$ID"
echo "/home/ruben/mscbk/$FN-$ID $x" >> /home/ruben/mscbk/map.txt
else
>&2 echo -e "\033[0;31mdoes not exist\033[0m"
echo " - could not find"
echo ""
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment