Skip to content

Instantly share code, notes, and snippets.

@CloverFeywilde
Created August 22, 2018 17:02
Show Gist options
  • Save CloverFeywilde/6c97b3e5ef3d9033ff7bc7b2e0c3b54b to your computer and use it in GitHub Desktop.
Save CloverFeywilde/6c97b3e5ef3d9033ff7bc7b2e0c3b54b to your computer and use it in GitHub Desktop.
Batch Remove or Replace characters from file names
#For use with a set of sequential files that contain extra zeroes. ex: file001.jpg, file002.jpg, file003.jpg ect.
#Replace <firstPartOfName> with everything up until the bit you want to remove. No brackets.
#replace <removeThis> with what you need removed, <replaceWithThis> for what you want in its place.
#You can leave <replaceWithThis> blank if you simply want to remove.
for file in <firstPartOfName>*; do
new_name=$(echo "$file" | sed -E -e 's/<removeThis>+/<replaceWithThis>/')
mv "$file" "$new_name"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment