Well, I had a simple thrill yesterday. I needed to make a nested directory, something along the lines of 1000-1999/1100-1199/1110-119. . .etc, so this would have been an unbearable task by hand. Create folder, name folder. . .

Fortunately, as a faithful adherent of the virtues of a programmer #1, laziness. I knew there had to be a fairly simple way. Well, I’m sure there is another way out their to make this work, but this was the best I could find. I ran this on my mac, but it should work in any *nix set up. Essentially you are defining elements and then adding those as place holders for the mkdir command. Be sure to add the -p option, this will make any parent folders which do not exist.

This example works to make directories for 700000-799999 that are nested down to the tens.


for tt in 0 1 2 3 4 5 6 7 8 9
do
for th in 0 1 2 3 4 5 6 7 8 9
do
for hun in 0 1 2 3 4 5 6 7 8 9
do
for ten in 0 1 2 3 4 5 6 7 8 9
do mkdir -p new/7"$tt"0000-7"$tt"9999/7"$tt""$th"000-7"$tt""$th"999/7"$tt""$th""$hun"00-7"$tt""$th""$hun"99/7"$tt""$th""$hun""$ten"0-7"$tt""$th""$hun""$ten"9
done
done
done
done

Advertisements