Skip to content

Instantly share code, notes, and snippets.

@phette23
Created August 12, 2015 00:11
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 phette23/b6156e3732134358c304 to your computer and use it in GitHub Desktop.
Save phette23/b6156e3732134358c304 to your computer and use it in GitHub Desktop.
remove leading zeroes Fish script
#!/usr/bin/env fish
# remove leading zeroes from JPG file names
# e.g. page001.jpg => page1.jpg
set start (pwd)
for dir in (ls)
echo "About to rename files in $dir"
# optional, makes me less afraid when I step through one folder at a time
read
# this works around cd-ing into a file; silence error & skip next command(s)
cd $dir 2>/dev/null
and begin
# file extensions could be .jpg, .JPEG, etc.
# only need to run twice as our names are like "page001.JPG"
rename -v 's/0([0-9])/$1/' *.jp* *.JP*
rename -v 's/0([0-9])/$1/' *.jp* *.JP*
end
# if we're not in the start directory, move back up
if [ ! $start = (pwd) ]
cd -
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment