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

A process will be writing to a set of directories, one for each hour using date +%H notation, so 00, 01, 02... 22, 23. I'm wanting to keep the leading 0 on single digit hours to keep sorted listings tidy.

I=00; until [ $I -gt 23 ]; do mkdir $I; let I=I+1; done

Has predictable effects of not keeping a leading 0 before the single digits. I could just go and make them by hand, but feel there should be a way to do this. Any ideas?

share|improve this question

3 Answers 3

up vote 11 down vote accepted
mkdir $(seq -w 00 23)
share|improve this answer
mkdir {0{0..9},{10..23}}

Or in Bash 4:

 mkdir {00..23}
share|improve this answer
+1 for not spawning a subprocess. – James Sneeringer Nov 11 '09 at 16:10
+1 , from my IRC hang out: "seq(1) is a highly nonstandard external command used to count to 10 in silly Linux howtos. Use one of these instead: for x in {1..10} (bash3.x) or for ((x=1; x<=10; x++)) (bash 2.04+) or i=1; while [ $i -le 10 ]; do ...; i=$(($i+1)); done (ksh/POSIX)" – Kyle Brandt Nov 11 '09 at 18:46
At least in Bash, you can do ((i++)) to increment a counter in a while loop (or elsewhere). Also, if you use double parentheses you can use <= and leave off the $: i=1; while ((i<=10)); do echo $i; ((i++)); done. – Dennis Williamson Nov 11 '09 at 19:16
for i in `seq -w 00 23`;do mkdir $i;done
share|improve this answer

Your Answer


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.