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?
3 Answers
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}
-
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). Jun 12, 2012 at 9:45
-
1
-
7
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)
-
7
-
11You 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.– phemmerJun 12, 2012 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. Jun 12, 2012 at 1:24 -
2
-
@Andrew yes I am aware of that, but I prefer to stay with the coding style of whatever I'm replying to.– phemmerJun 12, 2012 at 2:27
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.