Creating multiple directories simultaneously

Charlie Kester corky1951 at comcast.net
Fri Mar 26 15:49:11 UTC 2010


On Fri 26 Mar 2010 at 04:44:56 PDT Jerry wrote:
>On Fri, 26 Mar 2010 11:32:58 +0000, Daniel Bye
><freebsd-questions at slightlystrange.org> articulated:
>
>> On Fri, Mar 26, 2010 at 07:12:48AM -0400, Jerry wrote:
>> > I could have sworn that I saw a method of creating several
>> > directories, actually a parent direct and several sub-directories
>> > simultaneously; however, I cannot fine the documentation any longer.
>> >
>> > Assume I want to create a directory: FOO with three directories
>> > under it, foo-1, foo-2 and foo-3. I tried: mkdir -p foo {foo-1,
>> > foo-2, foo-3}
>>
>> Almost.
>>
>>  $ mkdir -p FOO/{foo-1,foo-2,foo-3}
>
>Thank you; that is exactly what I was looking for. I knew I had seen it
>somewhere before.

Or, for even less typing:

$ mkdir -p FOO/foo-{1,2,3}

Understand how this works, however, so you won't need to look it up
again, but can apply it yourself in whatever variation is needed. It's
called brace expansion.  Here's the first hit that comes up in Google,
which describes it fairly well:

http://snap.nlc.dcccd.edu/reference/bash1/features_11.html

This page is about the bash shell, but brace expansion works the same
way in tcsh.  It is NOT supported in tne Bourne shell.


More information about the freebsd-questions mailing list