1

I would like to add a numbered prefixes to all my folders in a folder.

For example, I have the following

  1. Picture_a.jpg
  2. Picture_b.jpg
  3. Picture_c.jpg

I want to have

  1. 01_Picture_a.jpg
  2. 02_Picture_b.jpg
  3. 03_Picture_c.jpg

I have 91 photos that I want to rename in this fashion. Thanks!

1 Answers1

0

A simple for loop to iterate over the files and printf to make the new filename should do it:

#!/bin/bash

i=1
for orig in *.jpg
do
    new=$(printf "%02d_%s" $i $orig)
    mv $orig $new
    ((i++))
done
Carl Norum
  • 219,201
  • 40
  • 422
  • 469