MYSYSAD.COM

Nested Inline For Loop for Recursive Directory Creation

· Shell & text · Files & disks

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