0

I want to make directories hal-01 to hal-30 on Linux. Is there a single command that can do this?

1
  • mkdir echo hal-{01..30} Feb 28, 2013 at 2:31

4 Answers 4

2

You can use the following command: mkdir hal-{01..30} (at least if you use a shell that supports this form of string expansions (bash does)).

To explain what it does:

$ echo {01..30}
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

As you can see the {01..30} got expanded to a number of arguments. This works if your curly braces occur within a string as well:

$ echo hal-{01..30}
hal-01 hal-02 hal-03 hal-04 hal-05 hal-06 hal-07 hal-08 hal-09 hal-10 hal-11 hal-12 hal-13 hal-14 hal-15 hal-16 hal-17 hal-18 hal-19 hal-20 hal-21 hal-22 hal-23 hal-24 hal-25 hal-26 hal-27 hal-28 hal-29 hal-30

Now mkdir accepts a number of arguments and will create a directory for each one. Thus you get what you asked for if you use mkdir rather then echo.

1
  • My Problem Solve With shall '# mkdir echo hal-{01..30}' thank's @yankee
    – user2115931
    Feb 27, 2013 at 15:34
2

Use brace expansion, such as like this: mkdir hal-{01..30}

4
  • that's not a regex.
    – dogbane
    Feb 27, 2013 at 15:22
  • That's indeed very true, which is why you should never post without coffee. Corrected.
    – SBI
    Feb 27, 2013 at 15:23
  • My Problem Solve With shall '# mkdir echo hal-{01..30}',
    – user2115931
    Feb 27, 2013 at 15:33
  • echo is redundant on that line...
    – SBI
    Feb 27, 2013 at 15:45
0

mkdir ~/example/folder{1..30} if you want 30

1
  • This will not create a directory hal-01 as it was asked for. It creates a directory hal-1 and counting.
    – yankee
    Feb 27, 2013 at 15:25
0

You can also use seq(1) for this, e.g.:

mkdir $(seq --format="~/example/folder/HAL-%02.0f" 1 30)

Can do other stuff, like different steps and so on. For some unscrutable reason, it computes with floats (!?), the printf(3)-like format has to be adjusted accordingly. This works even with plain shells that don't do funky expansions.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .