Last active
July 10, 2016 03:00
-
-
Save chilismaug/198dcaf6c78aa3bab8dc231da23e5028 to your computer and use it in GitHub Desktop.
bash to rename files with sequential numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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