I've got a web server which has files uploaded to it. There is a script which assigns them numeric IDs and stores them in a corresponding subdirectory.
I've now got 32000 of these uploads and that's too many for the server to handle in one directory. The script I'm using does have a way to "namespace" uploads so that ID 12345 - instead of sitting in /files/12345
- would sit in /files/namespaced/000/012/345
.
The code can deal with this just fine, but I now have 32000 subdirectories in the wrong naming style. What's the easiest way to go through my existing files and put them in the right place?
This assumes that the directory names don't have any odd characters such as spaces or newlines in their names and that there are no filenames that start with a dot.
Untested.
Another way to obtain the new directory name:
I did it a more manual way. the files were at the base level and I created all the folders and manually copied 1000 jpg files at a time in each folder. A part of the bash script was
I would just manually repeat the command with another folder until I'm done I also would just rename the files to a sha1 string if the file order is not important.