Skip to content

Instantly share code, notes, and snippets.

@rileyjshaw
Created February 1, 2022 16:23
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 rileyjshaw/85be6d9ab4b4c84436527df4b9651428 to your computer and use it in GitHub Desktop.
Save rileyjshaw/85be6d9ab4b4c84436527df4b9651428 to your computer and use it in GitHub Desktop.
Rename files to `01.ext`, `02.ext`, etc. based on output order of `ls`
#!/bin/bash
FILES=($(ls -tUr *.{png,jpeg}))
for i in "${!FILES[@]}"; do
mv "${FILES[i]}" "$(printf "%02d.${FILES[i]##*.}" "$((i + 1))")"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment