View Full Version : Generating nested folders with terminal

Mar 16, 2009, 03:42 PM
I am trying to work out the most efficient way to generate a series of empty nested folders in OS X.

I figure there must be a terminal command to do this, but I am a bit of a terminal n00b.

Also what is there a limit of how many nested folders OS X can support?



Mar 16, 2009, 04:03 PM
If you use the mkdir command with the -p option, it will create intermediate folders. For example mkdir -p ~/temp01/temp02/temp03 will create a temp03 folder inside a temp02 folder inside a temp01 folder inside your home folder.

EDIT: oops, forgot the flag in my example...fixed.

Mar 16, 2009, 04:05 PM
As far as I know there is no limit on the number of directories that can be nested. However, the longest an absolute path can be is 1024 characters (or whatever the value of PATH_MAX is). You'll probably start getting "file name too long" errors somewhere around the high hundreds of nested directories, depending on the lengths of their names.

And yes, mkdir -p is the answer. Manpages are your friend.

Mar 16, 2009, 04:05 PM
I found an older thread that I helped with that dealt with creating directories and sub-directories (http://forums.macrumors.com/showthread.php?t=354028&highlight=mkdir). Read through the entire thread. It involves writing a short bash script to do the job.