bash script snippets

file renaming

Rename all *.jpg files in a folder to 0001.jpg, 0002.jpg, etc.

#!/bin/bash
a=1
for i in *.jpg; do
  new=$(printf "%04d.jpg" "$a") #04 pad to length of 4
  mv -i -- "$i" "$new"
  let a=a+1
done