Skip to content

Instantly share code, notes, and snippets.

@discarn8
Created April 11, 2022 23:25
Show Gist options
  • Save discarn8/485ae6512a12cf2d444f0bb6d53bb0f0 to your computer and use it in GitHub Desktop.
Save discarn8/485ae6512a12cf2d444f0bb6d53bb0f0 to your computer and use it in GitHub Desktop.
Rename with overwrite verify
#!/bin/bash
IFS=''
echo -n "Enter text to rename: "
read -r rename
echo -n "Enter filetype to search (txt, jpg, pdf, etc): "
read ftype
while true; do
read -p "The text to rename is \""${rename}"\" and the filetype is \""${ftype}"\" - Is this correct? " yn
case $yn in
[Yy]* ) for i in *.$ftype; do
echo "Renaming $i";
mv -i "$i" "`echo "$i" | sed \"s/$rename//g\"`";
done;
break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
echo "Renaming done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment