Bash batch rename files in order
Try:
i=1; for f in *.jpg; do mv "$f" "1-$((i++))-3.jpg"; done
For example, using your file names:
$ lsIMG_20160824_132614.jpg IMG_20160824_132658.jpg IMG_20160824_132738.jpg$ i=1; for f in *.jpg; do mv "$f" "1-$((i++))-3.jpg"; done$ ls1-1-3.jpg 1-2-3.jpg 1-3-3.jpg
Notes:
When expanding
*.jpg
, the shell lists the files in alphanumeric order. This seems to be what you want. Note, though, that alphanumeric order can depend on locale.The sequential numbering is done with
$((i++))
. Here,$((...))
represents arithmetic expansion.++
simply means increment the variable by 1.