You are on page 1of 8

AIX for System Administrators

Practical Guide to AIX


Commands
CUT:
lspv | cut -c 6-7 lists the hdisks numbers (cuts the 6th and
7tn character (disk nubers))
dlnkmgr view -drv | grep -w 00000 | awk '{print $4}' | cut -d . -f 3
------------------------------------------------------------------------
--------
EXPR: integer arithmetic
! multiplication (\ is needed to tell * is
not a special character)
" diision
# remainder
$ addition
- substraction
e%pr & 6 $ 4 ' " ( )
------------------------------------------------------------------------
--------
FIND: recursiel! searches the director! tree
find " -%dev -t*pe f -name +c,r!+ -si-e $.0000c -e%ec ls -l {} /
" "here to #ind
-%dev looks onl! in the gien #s
-t*pe f "hat t!pe to look #or (#$ #ile% d$
direcor!)
-name +c,r!+ name to look #or
-si-e $.0000c search #or the gien si&e ('())))c $
greater than ()))) character (larger then ()kb!te))
-si-e $( search #or greater than (kb!te (blo*k si&e
is +(, b!te% that-s "h! ', is gien)
-e%ec ls -l {} / "hat command to e*ecute
(./$ it represents each #indings and \0 is
needed at the end o# line)
e1g1 #ind 2home -*de -name 3*1old3 -e*ec
rm ./ \0
-mtime -. #ile modi#ocation date is less then ( da!
('( means older than ( da!)
find . -name '!.ks0' -,k rm {} / this "ill ask i# the command (rm)
should be e*ecuted or not (much sa#er i# #ind is not per#ect)
find "etc"rc.d -ls it lists the #iles and dirs in the gien
dir
find "tmp"11 -e%ec awk '"func" {print 23456785}' {} / it "ill check
in 2tmp2bb i# an! #iles contains the "ord 3#unc3 and list those
------------------------------------------------------------------------
--------
GREP: (Global 4egular 5*pression Parser) 6he grep command searches #or
the pattern1
grep -i ignore case (small letter or capital)
grep -c displa!s onl! a count o# matching lines
grep -n sho"s line number at the beginning o# the
matching line
grep -v inert the sense o# matching% to select
non-matching lines
grep -w selects onl! "hole "ords
grep -l lists the name o# the #iles (once) "hich
contain matching line (grep -l paging)) *)
ps -ef | egrep 'ss0|ai%' select lines "ith ssh and ai*
errpt -a|grep -7. '6785' selects lines "ith 7A85 and sho"s ( line
a#ter that (A$ a#ter% 9$ be#ore)
------------------------------------------------------------------------
--------
HEAD, TAIL:
0ead filename displa!s #irst () lines o# the #ile
0ead -)0 filename displa!s #irst +) lines
tail filename displa!s last () lines o# the #ile
tail -)0 filename displa!s last +) lines
tail $.) filename displa!s the #ile starting #rom the (+th
line
tail -f filename used "hen "e are monitoring the #ile
(interactiel! sho"s ho" the #ile is changing)
------------------------------------------------------------------------
--------
LSOF:
756:;4<
-n no host name resolution
-9 not conerts port numbers to port names
ls,f -i sho" all net"ork connections
ls,f -i| grep 43:;56 sho"s "hat ports are "aiting #or
connections
ls,f -i | grep 5:;7<43:=5> sho"s current actie connections
ls,f -i tcp list onl! 6=P connections ("orks "ith udp
as "ell)
ls,f -i ?@p,rtA sho"s all connections o# a gien port (lso#
-i $,, or lso# -i $ssh)
ls,f -i B@0,stA sho"s connections to a speci#ic host (lso#
-i >(?,1(6@1(1+)
ls,f -i pr,t,c,l?Bip?p,rt this is the s!nta* #or net"ork #indings
(protocol$ tcp or udp% >ip$ an! ip address% port$ a port number)
ls,f -a -u @userA -i sho"s all net"ork actiit! o# a user (-a
combines -u and -i)
AB54% CID5B% P4;=5BB5B
ls,f -u @userA sho"s "hat is open #or a user (lso# -u
oracle)
ls,f @fileA sho"s "hat is using a #ile (lso#
2ar2adm2s!slog1log)
ls,f @direct,r*A sho"s "hat pids are using the #iles!stem
(director!) (it can be good i# "e cannot umount)
ls,f $> @direct,r*A sho"s "hich #ile is open b! "hich process
in a director! (lso# 'E 2usr)
('E "ill sho" recurciel! the open #iles%
other"ise onl! deice name "ould be sho"n)
ls,f -6 list all 7CB #iles
ls,f -c @c,mmandA sho"s #iles and net"ork connections a
command is using (lso# -c ssh)
ls,f -p @pidA sho"s "hat a proccess IE has open (lso# -p
FF++G+)
-----------------------------
HOW TO FIND WHAT FILES ARE OPENED BY A PID
1.
root>ai*,)$ 2root H ls,f -p 3.C660
=;88A7E PIE AB54 CE 6IP5 E5JI=5 BIK52;CC 7;E5 7A85
ocd F(?66) root F,r J45G ()%+ (,(+F 6?7)+ 2usr (2de2hd,)
(it "ill sho" the #iles!stem and the indode number (6?7)+))
2.
root>ai*,)$ 2root H find "usr -inum 6C70)
2usr2lpp2JJ2msg2enLAB2sec1cm1client1cat
------------------------------------------------------------------------
--------
ETACHARACTERS! "ARIABLES$
G45P BM5DD
single character 1 N
multicharacter 1* *
character range O*-&P O*-&P
begins a line Q 72A
ends a line R 72A
ariable 72A R
=D85 home director!
$9:. prompt s!mbol
set displa!s the alues o# all shell ariables
------------------------------------------------------------------------
--------
RP:
rpm -Ea sho"s "hat rpm packages are installed
rpm -El @package nameA sho"s "here the #iles are installed (rpm
-Slp 11 sho"s the absolut pathsNNN)
rpm -E --files1*pkg cdrec,rd list all the #iles on installed rpm
package
rpm -Ef "usr"1in"l*n% Suer! a #ile to #ind the source rpm
package
rpm -Ei @package nameA list in#ormation on an installed rpm
package
rpm -EF @package nameA list all dependencies on an! rpm package

rpm -iv0 0ttpd-(.(.G.ai%)...rpm install the rpm package
rpm -iv0 --f,rce !.rpm
rpm -iv0 --f,rce --n,deps @package nameA does not check dependenc!
(same can be done "ith 3rpm -Ah1113 #or upgrade)
rpm -e @package nameA remoes the rpm package
rpm -Ha sho"s "hich #iles are missing #rom the 4P8
database
rpm -Hv @package nameA eri#ies a package
rpm --re1uildd1 compress and rebuild the 4P8 database
"usr"s1in"updtvpkg enables the rpm command to recogni&e that
the libraries hae been installed
In some cases !ou might get an error about #ailed dependencies "hen !ou
install 4P8s on AIX (#or e*ample% error$ #ailed dependencies$
libX((1a(shrG1o) is needed b! tk-@1F1F-()1 8ost likel! the error occurs
because the rpm command does not recogni&e the shared librar!1 I# the
error occurs% check to see i# the X(( libraries are installed in the
director! 2usr2lpp2X((2lib1 I# the! are not installed% use the AIX
product media to install them1 A#ter !ou hae installed the libraries%
run the aboe command (updtpkg)1 6he command enables the rpm command to
recogni&e that the libraries hae been installed1
------------------------------------------------------------------------
--------
RSYNC:
8uch like cp% rs!nc copies #iles #rom a source to a destination1 Anlike
cp% the source and destination o# an rs!nc operation can be local or
remote1 rs!nc can resume a trans#er a#ter interruption0 it trans#ers
onl! those portions o# a #ile that di##er bet"een source and
destination0 and rs!nc can per#orm entire or incremental backups1
9! de#ault% rs!nc uses Becure Bhell (BBM) as its transport mechanism0
!ou can reuse !our machine aliases and public ke!s "ith rs!nc
rs*nc -av "tmp"11Irs30 "tmp"11 it "ill cop! the director!
(2tmp2bbLrsF)) and its contents under 2tmp2bb
rs*nc -av "tmp"11Irs30" "tmp"11 it "ill cop! the contents o# the
named director! but not the director! itsel# (check 2 at the end)
- option enables erbose messages
-a option (stands #or archie)% is
a shorthand #or -rlptgoE$
recurse% cop! s!mbolic links as
s!mbolic links% presere permissions% presere #ile times%
presere group% presere o"ner%
and presere deices and special #iles% respectiel!
rs*nc -n -av "tmp"11Irs30" "tmp"11 -n$ preie"s "hat "ill happen but
does not moe a single b!te (it is good #or testing)
rs*nc -av "tmp"11Irs30" ai%(?"tmp"11Irs(0 it "ill cop! the contents o#
the gien dir to the other host
(assuming the same login name
on the remote machine)
------------------------------------------------------------------------
--------
SORT:
cat "etc"passwd | s,rt -t? -n $(
-t? gies the delimeter character (here $%
dea#ult is the space)
-n numerical order
$( sort b! the Frd column
-r reerse order
df -m | s,rt -n $3 | egrep 'C.#|.00#' sorts b! the Gth column (T) o#
the #ilesstems% "hich are ?)-())T #ull
cat animals | s,rt $0.. sort the #ile animals b! the second
character o# the #irst "ord
ls -lF |s,rt -nk )|tail -(0 sorts the ,) largest #ile
lspv | s,rt -k..6n list hdisk in numerical order (lspUsort
-tk '( -n V--it is the same (delimiter is 3k3)
lspv | s,rt -k.J..) -k..6n list hdisks then paths in numeric order
------------------------------------------------------------------------
--------
TAR:
tar -cvf "tmp"file.tar . saes "here "e are to the
gien path (-c$ create% -$ erbose% -#$ #ile)
tar -cvf c,nf.tar c,nf creates con#1tar o# the
dir con#
tar -%vf "tmp"file.tar e*tracts the tar #ile (-
*$ e*tract)
tar -%vf -K "0,me"11 "tmp"file.tar it "ill e*tract the tar
#ile to 2home2bb
tar -tvf "tmp"file.tar list (eri#!) the content
o# a tar #ile
tar -cf - ! | g-ip -C A vmi.tar.g- makes tar and &ip "ehere
"e are
tar cvf - ,penss0).Gp. | g-ip -c A ,penss0).Gp..tg- creates tg& in one
command
#a$: %&11'1() D*$+,#o$S+$-+$: Canno# .$*#+ da#a +/#$a,#+d .*#0 #0+ #a$
,ommand:
A 1*2+ ,anno# 3+ 2a$4+$ #0an #0+ -a25+ s+# 36 52*m*#.
I changed these ulimit settings a#ter that it "as ;< (dont-t #orget to
logout and login again)
$oo#733829a$: :33 ; ,05s+$ 1s*<+='1 1s*<+80a$d='1 $oo#
$oo#733829a$: :33 ; ,05s+$ da#a='1 da#a80a$d='1 $oo#
------------------------------------------------------------------------
--------
TRUSS:
truss @c,mmandA it "ill sho" "hat s!stem calls a command
makes
truss -c -p @pidA it "ill trace a process (-c$ counts the
s!stem calls rather than displa!ing them% -p$ pid)
truss -d -p @pidA -,
truss -t ,pen lsps -a sho"s "hatis needed #or the gien command
(here lsps -a)
------------------------------------------------------------------------
--------
XARGS:
lspv|awk '{print$.}'|%args it "ill list the elements in a line
separated "ith space
cat list | %args -t rm "ill rm all the #iles "hich are in the #ile
list
ls | %args -t -3 {} mv {} {}.,ld it "ill rename to 1old all the #ile in
the current dir
-t it echoes the constructed command (trace
mode) (it is optional)
-3 {} insert each line o# the ls to that place
"here the ./ s!mbol appear
lsdev -Kc disk | %args -n. rmdev -dl remoes all the listed disks
-n. ( element "ill be passed each time to *args
(i# n, then the command "ill be created "ith , elements)
------------------------------------------------------------------------
--------
>IPPING:
g-ip-H sho"s g&ip ersion
g-ip file. &ip
g-ip -d file..g- un&ip
g-ip -C filename "ill &ip (and remoe the #ile
automaticall!)
gun-ip filename un&ipping it
g-ip -c file A file.g- it creates a &ip #ile but leae the
original #ile as "ell
A filename a#ter that original #ile can be emptied
c,mpress file. the original #ile "ill be deleted and a ne"
compressed #ile "ill be created "ith a 1K at the end
-cat file..L displa!s the compressed #iles ("ithout
uncompression)
unc,mress file..L uncompressing a #ile (the compressed one
"ill be deleted)
i# !ou receie this$
45n<*9 S6sD*$?82.#a$.4<
45n<*9: S6sD*$?82.#a$: F*2+ #oo 2a$4+
this is because g&ip (1,1G (or lo"er g&ip ersions) need a patch to
accept large #iles% "orkaround #or this problem$
4<*9 'd ', S6sD*$?82.#a$.4<@ #a$ /-1 '
------------------------------------------------------------------------
--------
OTHER:
file @filenameA sho"s the t!pe o# a #ile
diff file. file( compares onl! te*t #iles
cmp file. file( compares all t!pes o# #iles
dircmp dir. dir( compares directories
time cp file. "0,me sho" the time to accomplish the command
(godd #or per#ormance anal!sis)
ps $$ sho"s "hich shell is in use
ec0, $:=544 sho"s the current shell
printenv ie" enironmental ariables
cat -vet file sho"s tabs% enters111 as ie"able
characters
-v displa!s non-printing characters as isible
characters
-t displa!s tab as QI
-e displa!s enter as R
WWW s0 -%v @c,mmand...A #or troubleshooting% i# a command #ails%
!ou can see "here e*actl! it #ailed in the command scriptWWW
(sh -* e*portg rootg)
dd ifM"dev"-er, ,fM"0,me"user"11"4N<Ifile 1sM.m c,untM4000 it creates a
GG9 #ile
lmktemp @filenameA @si-eIinI1*tesA it creates a #ile "ith gien si&e
alias dirM'ls' creates an alias
unalias dir remoes an alias
set - unset
df -g | awk '{sum M sum $ $3} 56> {print sum}' it sums up the #s in
gigab!te (b! the Frd column)
f,r i in Ols -l | grep ,ld | awk '{print $C}'O / d, du -sk $i/ d,ne |
awk '{sum M sum $ $.} 56> {print sum}'

You might also like