Thursday, May 10, 2007

Nested Inline For Loop for Recursive Directory Creation

The inline script will create 5 recursive directories and recursively change the directory permission bits to read, write and execute for the owner and for all others read and execute.

Here's the syntax.

#sh
#cd to_creation_dir
# for i in dir_1 dir_2 dir_3 dir_4 dir_5
> do
> for j in 2005 2006 2007
> do
> for k in jan feb mar apr may jun jul aug sep oct nov dec
> do
> for l in mon tue wed thu fri sat sun
> do
> for m in log1 log2 log3 log4 log5
> do
> mkdir -p $i/$j/$k/$l/$m; chmod -R 755 $i/$j/$k/$l/$m
> done
> done
> done
> done
> done

4 comments:

Justin said...

for x in dir_{1..5}/{2005..2007}/{jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec}/{mon,tue,wed,thu,fri,sat,sun}/log{1..5};do mdir -p $x;done

esofthub said...

Justin, i'll have to try that. Thanks

Anonymous said...

Manual Directory Submission

Anonymous said...

the question is, how do you delete this if you happend to _not_ restrict this to 5 sublevels, and now it created about infinite sublevels, and rm complains about not being able to delete them... ;)