SysAdmin Blog, TechTips and Reviews

An (ex) System Administrator's Blog



Archives Posts

Used Another ‘For… DO’ Loop

June 6th, 2008 by elizar

The last post, was used to chmod a list of home directory.

I used another application for that ‘for..do’ loop again… it’s climbing my favorite script command list.. :) second only to ‘while…do’.. :)

for X in `ls -last | grep 2006 | awk ‘{print $9}’`
do
rm -rf $x
done

bye bye 2006 directories!

Filed under Commands, Scripting having No Comments »

Archives Posts

Looping Through a List of Arguments (bourne)

May 31st, 2008 by elizar

The Bourne shell for loop looks like this:

    for arg in list
do
...Handle $arg...
done

Real life application.. :)

# ls -l | awk ‘{print$9}’

user01
user02
user03
user04
user05
user06
user07
user08
user09
# pwd
/home
# for x in `ls -l | awk ‘{print$9}’`
> do
> chown $x $x
> done
# ls -aslt
total 136

.. yeah you know what the output is.. :)

Filed under Scripting having 1 Comment »

I was here...