Tell me more ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I need to create folders starting from 00 to 99 (00, 01, 02, 03, etc....) in several hundred places. Is there a single line command that will let me do that?

share|improve this question

2 Answers

up vote 39 down vote accepted

mulaz's answer is correct, but many people say seq is evil beacuse most shells will let you do the following

mkdir {00..99}

However in some older versions of bash, 0-9 arent padded, so you would have to do

mkdir 0{0..9} {10..99}
share|improve this answer
9  
+1 Should be the accepted answer IMHO. Not only is this idiomatic Bash, it doesn't require using an external program (which seq is). – Trollhorn Jun 12 '12 at 9:45
1  
This is how it should be done. – phoxis Jun 12 '12 at 15:09
7  
The following works too: > mkdir {0..9}{0..9} – Orieg Jun 12 '12 at 21:37

Will this do?

for i in `seq -w 0 99`; do mkdir $i; done

does a loop for numbers 0-99, and "-w" sets the equal width (0 padding for 0-9)

share|improve this answer
Yup, this works perfectly. Thanks! – k1lljoy Jun 12 '12 at 0:15
6  
seq -w 0 99 | xargs mkdir would also do the job. – Jay Jun 12 '12 at 0:24
10  
You can ditch the loop and just do mkdir $(seq -w 0 99). Or use backticks instead of $(), but I can't put backticks in because of serverfault syntax. – Patrick Jun 12 '12 at 0:52
@Patrick: Yes, you can: mkdir `seq -w 0 99` (I couldn't avoid the extra space). See here, but it looks like the trick of including spaces in the delimiters doesn't work here. – Keith Thompson Jun 12 '12 at 1:24
1  
@Patrick backticks are bad: mywiki.wooledge.org/BashFAQ/082 – Andrew Jun 12 '12 at 2:21
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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