Better way to create a folder for each month, with another folder inside of each
I was going to do this manually, but figure it might be a good question to ask, as i'm sure there is a much slicker way to do it.
What I want to do is inside my directory /2012 I want to make a folder for each month of the year, like 01-2012, 02-2012, etc. then inside each ##-2012 folder, I want to make a folder named processed. Last year I manually did mkdir's for each one, but is there some way to better create these? |
Code:
for i in {01..12}; do mkdir -p $i-2012/processed; done Markus |
Wow, that worked great, except that it didn't do 01, 02; it did just 1, 2, etc. Is there a way to make it do the leading zero for even the single digit months?
|
Which shell are you using? here I have (with Bash 4.2.37)
Code:
markus@samsung:~/2012$ ls Markus |
BashFAQ/018 - leading zeros in a loop
Includes: Bash 3, Bash 4, POSIX shell, ksh and BSD style examples. |
bash 3, its an older box.
I copied and pasted what you typed, so I had the 01 |
Thanks druuna, I did a for i in 0{1..9} and a for i in {10..12} and that did it. I wasn't sure how to combine them.
Thanks to you too Markus. |
Quote:
Code:
for i in {0{1..9},10,11,12}; do mkdir -p $i-2012/processed; done |
Ah cool, thanks. I wasn't sure how to combine them. Wasn't sure if you should do a 10..12 or like how you did it.
|
In bash 4.2 you can forgo the for loop and just use:
Code:
mkdir -p {01..12}-2012/processed And just to show that there is always another way to do everything in UNIX ;) Code:
seq -w 1 12 | xargs -i -- mkdir -p {}-2012/processed |
All times are GMT -5. The time now is 01:21 AM. |