I have a directory called "images" filled with about one million images. Yep.

I want to write a shell command to rename all of those images into the following format:
original: filename.jpg
new: /f/i/l/filename.jpg

Any suggestions?

Thanks,
Dan

#!/bin/bash
for i in *.jpg; do
  c1=`expr substr ${i} 1 1`
  c2=`expr substr ${i} 2 1`
  c3=`expr substr ${i} 3 1`
  dir=${c1}/${c2}/${c3}
  echo mkdir -p ${dir}
  echo mv $i ./$dir
done

You will want to test that the file name is at least 3 characters

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.