looking for a way to pre-create directories on linux to be used to store a large number of files.

We will be generating file ids using a GUID - I need to keep a copy of these files on a linux web server. I plan on using subdirectories to split up the files (it's ext3)... so for example, the filename 055c102b-62fb-4671-a3c7-68b9515ec53e.swf would live in /data/files/0/5/5/055c102b-62fb-4671-a3c7-68b9515ec53e.swf (taking the first 3 characters as directory names)

My question is - how to create the /data/files/?/?/?/ directories ahead of time? Where ? could be a-z or 0-9

link|improve this question
feedback

1 Answer

up vote 13 down vote accepted

Using Bash I think it is:

mkdir -p {{a..f},{0..9}}/{{a..f},{0..9}}/{{a..f},{0..9}}

Might make more sense to just to create them as needed though.

I think since it is hex, this gives 16^x directories for x = tree depth, but someone from stackoverflow can probably explain that better and/or confirm if that is accurate.

link|improve this answer
That's exactly it. – Dennis Williamson May 7 '10 at 14:35
Very cool - thank you so much! Works perfectly. The reason I (think I) need to create them ahead of time is because the external process that will be uploading these files via scp/sftp assumes the directories exist. Do you see any downsides to doing this? – Erik Sorensen May 7 '10 at 14:54
I guess the only real downside that comes to mind is that maybe in theory access will be a tad bit slower as each level of the tree will be a little bit wider until it is full. That sounds like BS to me though as a I type it (especially with dir_index enabled on ext3/4), so no, no real downside that I can think of. I would recommend that maybe you go over to stackoverflow and ask if 3 is the right tree depth if you haven't already given that a lot of thought (Can't really hurt, at least not too much). – Kyle Brandt May 7 '10 at 15:04
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.