« A Case of Extreme Uptime | Main | Configuring Cluster Notifications »

December 04, 2012


TrackBack URL for this entry:

Listed below are links to weblogs that reference Command Line Shortcuts:


I think the lscfg command can accept this:
lscfg -vl fcs* | grep Net

I skip spaces before and after the pipe key, unless I'm showing someone else or putting it into documentation. So you could make it shorter using:
lscfg -vlfcs*|grep Net

and the lsdev command can be shortened using xargs. BTW, with lsdev you don't need the upper case C, although everyone uses it. Once again, give your space key a rest:

lsdev -cdisk|awk '{print $1}'|xargs -n1 rmdev -dl

The other one I use is when I am in a long command line that I want to cancel with ctrl-c, but may come back to, I turn it into a comment with two keys: Esc and #
(Okay. I admit, the # key requires you to press two keys). Then it's in the shell history for easy recall with Esc k.

Loved the tip to press v to turn it into a vi session. I've done it thousands of times by mistake and wondered which key did it.


I use

for D in $(lsdev -c disk -F name)
S=$(bootinfo -s $D)
printf "$D\t$S\n"

... all the time


I use
lsdev -c adapter -l fcs* -F name | xargs -n1 chdev -a reserve_policy=no_reserve -l

... all the time too

The part about looping on a set of values reminded me of "seq". I missed it from my Linux days, and so had written an imitation in perl before realizing that the "AIX Toolbox for Linux Applications" page at has it packaged in the coreutils RPM.

i'm using this one all the time (small variation of the above):
#lsdev -c adapter -l fcs*|awk '{print "chdev -l" $1" -a reserve_policy=no_reserve}'|ksh
...which gives me the output of the commands if i take out the "|ksh" part, useful to check before executing the commands.

My favorite trick for when I'm doing things with devices names is to change into the /dev directory and then use a 'for' loop to loop through the devices I need:

# cd /dev
# for D in hdisk*
> do
> printf "%s: " $D
> bootinfo -s $D
> done
hdisk0: 140013
hdisk1: 140013
hdisk10: 25600
hdisk11: 25600
hdisk12: 25600
hdisk13: 107550
hdisk14: 107550
hdisk15: 107550
hdisk16: 107550
hdisk2: 140013
hdisk3: 140013
hdisk4: 140013
hdisk5: 20480
hdisk6: 20480
hdisk7: 20480
hdisk8: 20480
hdisk9: 25600
hdiskpower0: 20480
hdiskpower1: 25600
hdiskpower2: 107550

R=0 root@hostname /dev

When using the v key to pull the command line into vi, it is important to remember that you are committed to running something at that point. If you try to :q!, it will run what you started with. So once in vi, if you decide to abort, you have to either comment out the command or delete everything and then :wq

This works wonders for getting the fcs name, location, and wwpn.
lscfg -vl fcs*|egrep 'fcs|Network'|awk '{print $1,$2}'

If you're running ksh93 for your shell, to get the 12 thru 25 increment, you can use the more "C-like" structure:

# x=11;while (( (x++) %3C 25 )); do
> rmdev -dl hdisk$x
> done

I also like combining output from different commands into a more column-oriented "report." Then you can pipe the output from the while loop to awk to pick out exactly what output you like to see:

# x=11;while (( (x++) %3C 25 ))
> do
> print -n "hdisk$x:\t"
> print -n "$(lsdev -l hdisk$x) "
> print "$(lspv hdisk$x|grep 'TOTAL PPs:')"
> done | awk '{print $1, $3, $4, $11, $12, $13, $14"MB"}'

Occassionally we have a volume group with several filesystems, usually with nested mounts (/a, /a/b, /a/b/c). Here is a quick way to mount all the filesystems in the volume group in the proper order. This comes in very handy when dealing with clusters

lsvgfs some_vg|sort|while read fs; do mount $fs; done

With minor modifications this can be used to umount the filesystems in the proper order. Simply change 'sort' to 'sort -r', and 'mount' to 'umount'.

I'm a fan of the least known command "apply", so for you first command.

apply "lscfg -vl fcs%1" 0 1 2 4 | grep Net

For your for loop, why not use "while :" or even shorter form for all the script.
while df
sleep 5

(either way around)

For the command listed as;
lsdev -cdisk|awk '{print $1}'|xargs -n1 rmdev -dl

I always find the awk not required, just select the correct field (-r name)
apply "rmdev -dl %1" $( lsdev -cdisk -rname )

I have found that using ctrl c and :q! successfully gets me out of the v key command pulled into vi.

The comments to this entry are closed.