Skip to content

Instantly share code, notes, and snippets.

@chilismaug
Last active July 10, 2016 03:00
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 chilismaug/198dcaf6c78aa3bab8dc231da23e5028 to your computer and use it in GitHub Desktop.
Save chilismaug/198dcaf6c78aa3bab8dc231da23e5028 to your computer and use it in GitHub Desktop.
bash to rename files with sequential numbers
//Beauty in one line
ls | cat -n | while read n f; do mv "$f" "$n.extension"; done
change extension with desired PNG, Jpg or some-other.
//Try to use a loop, let, and printf for the padding:
a=1
for i in *.jpg; do
new=$(printf "%04d.jpg" "$a") #04 pad to length of 4
mv -- "$i" "$new"
let a=a+1
done
//use mv -i -- "$i" $new" if you do not want to automatically overwrite existing files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment