Take the 2-minute tour ×
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

3 Answers 3

up vote 40 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! –  user11350 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

I know this is old, but my recommendation would be:

for i in seq -f %02g 0 99 ; do mkdir $i ; done

the -f %02g ensures it stays at least two characters, such as 00 or 99, and will still allow 3 character numbers past 99 so if you have 100 it will not become 001. It will be 00-99 100 instead of 001-100 such as the -w does.

share|improve this answer

Your Answer

 
discard

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