I have a linux webserver with about 25.000 images in one directory. They are all lowercase and in the format two letters, three digits and jpg as the extension. Because that many files in one folder is getting difficult to manage I want to move them to subfolders based on the first two letters of the filename like this:
/images/ab123.jpg --> /images/ab/ab123.jpg
/images/ab383.jpg --> /images/ab/ab383.jpg
/images/sk234.jpg --> /images/sk/sk234.jpg
I already managed to list all about 250 different letter combinations and create subdirectories:
ls | awk '{print substr($0,0,2)}' | uniq | xargs mkdir
But I can't manage to move the files. Any ideas?