Handy Solaris Commands
prtconf - /usr/sbin/prtconf System confguration information
prtdiag - /usr/platform/sun4u/sbin/prtdiag Diagnostic and confguration
information.
Use the -v option for additional detail.
prtfru - /usr/sbin/prtfru FRU hierarchy and SEEPROM memory contents. Use
the l option to display hierarchy. Use the -c option to display SEEPROM data.
psrinfo - /usr/sbin/psrinfo Date and time each CPU came online processor
cloc! speed. Use the -v option to o"tain cloc! speed and other data.
showrev - /usr/bin/showrev #ard$are and soft$are re%ision information. Use the
-p option to sho$ soft$are patches.
prstat - /usr/bin/prstat Sho$s running processes and their memory utili&ation
Unix/Solaris: One-Liners
Source: http://www.kevlo.com/e!s/unix"commands.txt
--> chan#e $ile date stamp
touch t 199906042020 filename
--> move partitions
ufsdump 0f - /dev/rdsk/c0t0s0s0 | (cd /home ufsrestore !v -"
--> lay down $ile system with %& min$ree and inode density
ne#fs m1 i$1920 /dev/rdsk/c0t0d0s0
--> check $ile system
fsck /dev/rdsk/c0t0d0s0
%& startin# sy!ase
lo'in as s()ase* run& +/install/,-./012304
%& lo##in# in as sy!ase sa
is5l -- sa 6pass#ord>
--> dump a partition and pipe to #'ip. 7atch > 282 limit
ufsdump 0f - /home | '9ip - >/tmp/home+dump+'9
--> rewind o$$line a tape
mt f /dev/rmt/0 re#offl
--> only allow ())*+ $or user /tmp access
s#ap - /tmp tmpfs (es 0:;4<=00>
--> ver!ose interactive restore
ufsrestore ivf /dev/rmt/1
--> remove a printer $rom a class
lpadmin p level?-line1 r level?-line
--> truss a command
truss -f -o /tmp/lo'+t!t
--> ,-+. $eed a script into sy!ase
is5l -rfe/!fer --user -@pass#ord -is5lscript >>)lah+t!t
--> make a printer class
lpadmin p level?-line1 c level?-line
--> remove level/-line/ printer $rom printer class level/-line
lpadmin -p level2-line2 -r level2-line
--> add level/-line( to printer class
lpadmin -c level2-line -p level2-line=
--> ,-+. how to chan#e your password in is0l
sp/pass#ord pass#ord* pass#ord-ne#
--> move a directory
tar cf - +/'ames | (cd /tmp tar !v2pf - "
--> ,-+. run a sy!ase script1 and dump to $ile
A:0%B -iA0C,:@DE:B4 --A-04, -FAF3D32304 -@A@300/4.C >> A0C,:@DBG8E:B4
--> move a directory to another server
tar cf - +/'ames | rsh )ruce( cd /tmpH tar !v2pf -
--> check $or SU2- S32- $iles
ncheck -E ufs -s /dev/dsk/c=t0d0s
-- remove core $iles
find / -name core e!ec rm f IJ H -o fst(pe nfs prune
--> re!uild man pa#es
catman # > man-pa'e-director( or /usr/li)/make#hatis
--> vi command to show special characters
& set list
--> addin# an account
useradd -u 120 ' dls -d /apps/dls s /)in/ksh -c KcommentK -m dls
--> create a mys0l data!ase
m(s5ladmin -uroot -ppass#ord create e)s
--> startin' m(s5l data)ase
/etc/rc+d/init+d/m(s5l+server start
/usr/local/)in/safe/m(s5ld
--> 2nvoke C456 module install
perl >C@3. eshell
--> dump to 'ip
ufsdump 0f - /files(stem | /opt/local/'9ip - > /tmp/dump+'9
--> shutdown mys0l data!se
/usr/local/)in/m(s5ladmin shutdo#n -ppass#ord
/etc/rc+d/init+d/m(s5l+server stop
--> test the loadin# o$ a module
@4,B/FB/F42-8<2?? perl -e Luse C8:L
--> shows open $iles
fuser cu /
--> 7ritin# a -aemon&
1+ edit /etc/services
add service and port+
2+ edit /etc/inetd+conf
add in& ed#ardd stream tcp no#ait root /)in/sh /)in/sh /home/se!tone/)in/04,M4,+mine
=+ kill N-@ inetd+conf
--> how to mount a $ile system
mount /dev/dsk/c=t0d0s4 /apps/data/eas(soft/F4MD
--> look at sar lo#
sar f /var/adm/sa/sa24
--> write $ile checksums and si'e
cksum filename
--> show stora#e array in$o
ssaadm displa( /dev/rdsk/c1t?d2s0
--> sho# all disks on device d
lu!adm displa( d
--> examine $or a speci$ic OS $in#erprint
nmap s0 -p $0 -G -v 6host> < e!amine G0
--> show print 8o!s
/usr/uc)/lp5 @level6
--> Scan $or known ports. lo# it. do OS scan.
nmap s0 -E -o foo+lo' -v -G ###+foo+com//24 <
--> show status o$ printer
/usr/uc)/lpc status
--> make a swap $ile:
dd if</dev/9ero of<s#apfile )s<1024 count<6??=?
mks#ap +/s#apfile
chmod 600 +/s#apfile
s#apon +/s#apfile
--> show open $iles $or process
lsof p @:F
--> show open $iles $or all 9C4 connections
lsof iDC@
--> show open $iles $or internet address
lsof -iDC@O10+20+2+9
--> as a!ove
lsof -i O10+20+2+122
--> examine tcp ports
lsof -iDC@Osarah&1-?0000
--> show open $iles $or user.
lsof u username
--> show processes that has the $ile in use.
lsof /apps/cms/4C>0-0erver
--> show open $iles and retry every : seconds
lsof p process-id r ?
--> mount a $loppy
mount -t vfat /dev/fd0 /mnt/flopp(
--> check here $or de!u##in# processes and errno.h $or errors
/usr/include
/usr/include/s(s
/usr/include/s(s/errno+h
--> scp a whole directory1 preserve mods
sudo scp -prv devel #e)adminO20=+19+12=+140&/home/httpd/c'i-)in
--> take processor / and ( o$$line.
psradm -f 2 =
--> show processor stats ver!ose.
psrinfo v
--> how to skip #rant ta!les in mys0l ;over ride security<
/usr/local/li)e!ec/m(s5ld -0'
--> how to $eed in an S=L pro#ram
m(s5l 6create/ta)le+s5l
--> rm all $iles in directories
find + -t(pe f -e!ec rm IJ H
--> dump packets to a capture $ile
sudo snoop o /tmp/tcp+t!t cp
--> !ackup one liner
tar cvf - /home/e)s | '9ip - > e)s+tar+'9
--> Look at selected packets in capture $ile
sudo snoop -i /tmp/tcp+t!t
--> un'ip and pipe to tar
'9ip -dc 6km(s5l-1/1/6/tar+'9 | tar !vf -
--> watch packets $rom two servers.
snoop sarah )ruce(
--> ena!le ip mas0ueradin#
/s)in/ipchains -@ for#ard F4.1
/s)in/ipchains -3 for#ard -s 10+100+100+100/$ -P >30%
-> view su lo# $ile
cat /var/adm/sulo'
--> esta!lish a de$ault router or #ateway+
echo Ksa'acit(+comK > /etc/defaultrouter
echo K10+100+100+100 sa'acit(+com sa'acit(K >> /etc/hosts
chan'e /etc/nss#itch+conf so that hosts has files* dns
edit resolv+conf put in
search +
nameserver 20=+Q+1=2+9$
--> turn o$$ automounter on /export/home.
vi /etc/auto/master* comment out /e!port/home
--> con$i#uration $ile $or sudoers
/opt/local/etc/sudoers
--> )uildin' ssh-1+2+2Q on !$60olaris2+6 needed a fe# thin's&
/usr/open#in/)in in path
/usr/!p'4/)in in path
declare 3,<K/usr/!p'4/)in/arK
declare .>/@3DN<K/usr/!p'4/)in/nmK
--> snoop network packets and #et si'e and time stamp entries.
snoop -0 -ta empa1
--> access perl C456
perl ->C@3. -e shell
install F2:
--> search $or no password entries and lock all accounts.
for i in Rpass#d sa | 'rep .@ | a#k SIprint A1TR
do
echo Ulockin' AiV
pass#d l Ai
done
--> delete $rom a tar
tar --delete -f fs/)ackup/0unda(+tar home/e)s/tmp
--> >xample on !ackin# up $iles to tape. *ust speci$y non rewindin#1 else you will over-
write the $iles.
for file in RlsR
do
echo Ksendin' Afile to tape+++K
echo RdateR
tar cvpf /dev/rmt/0n Afile
done
--> makin#/addin# a partition.
1+ use fdisk to make a parition+
2+ mkfs -t e!t2 -c /dev/hda11
=+ mount -t e!t2 /dev/hda11 /opt2
4+ update /etc/fsta)
--> re!uild the windex $ile
catman # > /usr/share/man
--> execute tar on remote host sarah and send tar!all to standard output1
#hich )ecomes standard input for tar !vf and the file 'ets dumped locall(*
in this case on cra#l+ (ou have to cd to dir )efore tar or else (ou
#ill include path in tar
ssh ma''ie Kcd AF:,.3>4 tar cvf - A2304.3>4K | (cd AD@3DN tar !vf - "
--> dump a remote $ilesystem and send it to local tape drive+
ssh -! Af# /usr/s)in/ufsdump 0cf - Afs | dd o)s<6=k of<AD3@4
--> encrypt $ilename % and output to %.crypt $ile
cr(pt 6 1 > 1+cr(pt rm 1
--> decrypt $ilename %.crypt and stdout to screen
cr(pt 6 1+cr(pt
--> send a $ile to tape
tar cvpf /dev/rmt/0 filename
--> 0uicker way to search and replace in vi
& Ws/e!istin'/ne#/'
--> shows where and which shared li!rary $iles an application uses.
ldd )inar(
--> shell script stu$$:
X repeat a command 100 times
!<100
#hile Y A! -'t 0 Z
do
command
!<A((A!-1""
done
--> 0omethin' ver( important to remem)er a)out partitions
:t is important to note that C(linder 0 contains the diskla)el* #hich
contains the partition ta)le+ 3 normal files(stem can )e placed
startin' at C(linder 0* since it #ill not touch the diskla)el+
:f (ou la( do#n a ra# device* for a data)ase* over C(linder 0*
then (ou #ill completel( lose all (our partitions+ 1ou #ill then
have to restore the diskla)el* and )ackup from tape if (ou happen to do this+
--> move a partition
find + |cpio -pdm /apps
--> cron structure
min hour da(-of-month month #eekda( command
--> 4atch-ia# 9ool. 8et patches from&
http&//sunsolve+sun+com/private-c'i/patchpa'e+pl
patchdia'+!ref is availa)le at& http&//sunsolve+sun+com/sunsolve/patchdia'/
/opt/local/)in/patchdia' -! /opt/local/li)/patchdia'+!ref > patchdia'+Runame -nR
--> command showin# system parameters
/usr/s)in/s(sdef
--> 3et 5m!ient 9emperature o$ Server
/usr/platform/0-.7*-ltra-4/s)in/prtdia' -v
--> #ood ps $ormattin# showin# percent cpu $irst.
ps -edf -o pcpu*pid*user*ar'
--> $ull details on ps
/usr/)in/ps 3 -o user*pid*pcpu*pmem*vs9*rss*tt(*s*stime*time*ar's
--> chown the hidden $iles as well.
find + -print -e!ec cho#n -, se!tone&staff IJ H
--> Dhe nsradmin command is a command-line )ased administrative
pro'ram for the .et7orker s(stem+ .ormall( nsradmin monitors
and modifies .et7orker resources over the net#ork+
/usr/s)in/nsr/nsradmin
--> Spray a server
-c num)er of packets
-d dela( in microseconds
-l pakcet si9e in )(tes
/usr/s)in/spra( -c 1 d 20 -l 4096 ma''ie
--> 9urn on !old.
)old<Rtput smsoR
off)old<Rtput rmsoR
echo KAI)oldJ1ou must )e the HKrootHK user to run this script+AIoff)oldJK
--> #ood way to send a dir to tape
tar cf /dev/rmt/0n director(
--> example o$ !rin#in# up an inter$ace
ifconfi' hme0&1 inet 10+2+2?+?2 up
--> show all connections
netstat f inet
--> rpcin$o makes an ?4C call to an ?4C server and reports
what it $inds.
rpcinfo -) =90109 2 | sort -u
--> rewind a tape $ast
6 /dev/rmt/0
--> show loaded modules
/usr/s)in/modinfo
--> $ind world reada!le $iles and dirs
find / -t(pe d perm -2 print
find + -t(pe f perm -2 -print
--> addin# in a !oot alias1 e#:
)oot sarahroot1 s
nvalias sarahroot1 /s)usO1f*0/sun#*fasOe*$$00000/sdO9*0&a
--> clever way to archive
tar cvf - Rfind + printR >/tmp/dumpfile+tar
tar !vf - 6/tmp/dumpfile+tar
--> tee to a $ile
echo K0tart Fate/Dime& RdateRK | tee -a ABG8/E:B4
--> read a snoop $ile
snoop -i an9-telnet+snoop
--> write a snoop lo# ;this will count the num!er o$ connections1 which is pretty neat<.
snoop osnoop+lo' sarah
--> set de$ault run level. : $or #ui.
/etc/initta)
--> show all exported $ilesystems
sho#mount -e cra#l
--> shows all con$i#ura!le varia!les $or tcp inter$ace.
sudo ndd -'et /dev/tcp
- [
e'&
sudo ndd -'et /dev/tcp tcp/conn/re5/ma!/5
12$
ndd /dev/arp H[
ndd /dev/ip H[
ndd /dev/tcp H[
ndd /dev/udp H[
ndd /dev/icmp H[
--> set sticky !it on #roup $iles1 only the owner can chan#e the mode.
--> the \l is mandator( file and record lockin' #hile a pro'ram
--> is accessin' that file+
chmod '\s*\l file
--> print duplex landscape @ 0udrant printin#
mpa'e t l 4
--> install a patch
installpatch +
--> check to see i$ a patch has !een installed
sho#rev p |'rep packa'e name
--> un'ip1 untar in a /tmp directory
9cat 104Q0$-16+tar+'9 | ( cd /tmp sudo tar !vf - "
--> check out revision level on ssa controller
/usr/s)in/ssaadm displa( controller
--> un'ip and untar a $ile without havin# to create an intermediate tar $ile
sudo '9ip -dc /tmp/2Q0?99/post-4GF+tar+'9 |tar !vf -
--> selectively extract $rom a tar archive
tar !vf /tmp/iona+tar +/iona/+sh/histor(
--> send a !unch o$ $iles to tape
tar cf /tmp/rules+tar rule)] o)Pects+C ]+7
--> examine section : o$ man
man -s ? si'nal
--> shows si#nals and de$initions o$ structures1 e# si#action
/usr/include/s(s/si'nal+h
--> location o$ the limits $ile on solaris
/usr/include/limits+h
--> send an attachment via email $rom command prompt
uuencode file+tar+'9 file+tar+'9 | mail! s U)ackupV rootOcra#l
--> 'ero a $ile
cat /dev/null > isam+lo'
--> #ood way to restore $rom cdrom a !inary $ile
9cat 6 /cdrom/cdrom0/0olaris/2+6/@roduct/0-.7csu/install/reloc+cpio+; |
cpio idm usr/li)/fs/ufs/ufsrestore
--> runnin# su as a user then ssh
su - dls-@,GF -c K/opt/local/)in/ssh drp-sta''er HKcd /tmp /)in/lsHK K
--> veri$y a new$s $ormat
sudo ne#fs .v /dev/md/dsk/d96
--> makin# lost"$ound. must !e A%B/ !ytes in si'e+
mkdir +/lost\foundcho#n root +/lost\found ch'rp root +/lost\found chmod Q00 +/lost\foundT cd
+/lost\found
nofiles<0 #hile Y KAnofilesK -le 6?0 Z do /usr/uc)/touch Anofiles nofiles<Re!pr Anofiles \ 1R
done
--> execute lynx
l(n! -cf' /usr/li)/l(n!+cf'
--> sed search example
sed L/0epH 2?/^d /castill/^dL /var/lo'/s(slo
-->should only !e used at the >>4?O*
)oot r
--> should !e used at sin#le user mode
re)oot -- -r
--> should !e used in multiuser mode
touch /reconfi'ure
--> per$ormin# a remote dump
find >E3010
|cpio -oc |'9ip -c
|ssh )ruce( -l chaup dd o)s<1$k of</dev/rmt/0n
- to extract -
cd /ssa/emphas(s/s()ase/dump
dd i)s<1$k if<6D3@4 F4M:C4>|'un9ip -c |cpio idc
--> !oot !lock located here+
/usr/platform/Runame iR/li)/fs/ufs
--> #ettin# a server on the network
add hosts entr( for :@ address
clear confi's& ifconfi' pe0 unplum)
ifconfi' pe0 10+20+2+2Q netmask 2??+0+0+0 up
route add default 10+20+0+1 1
verif( the routin' ta)le& netstat rn
add resolv+conf entr(& domain ra)o)ank+com+au nameserver 192+192+192+2?2
edit /etc/nss#itch+conf chan'e hosts to files* dns
lesson here is to unplum) interface* and let ifconfi' setup the routin'+
if (ou specif( an ip address and a netmask it #ill mana'e
the routin' and the )roadcastin'+
--> $ind all1 $iles associated with 42- ///@)
/usr/proc/)in/pfiles 22240
find file )ased on inode
find i num)er
Uncheck i num)er
--> #ood redirection example
+/a+out 6/etc/termcap | (sleep 10 cat" >trash
--> synchroni'e $iles $rom one server to another. Dhis is useful for
s(nchroni9in' data)ase dump files* )inar( files* etc+ Dhis is definitel( a po#erful tool+
rs(nc -av9 -e ssh --rs(nc-path<K/usr/local/)in/rs(ncK Rp#dR m(host+com&/home/e)s/pu)lic/html
--> >xample 5wk Script
X run #ith a#k -f/tmp/1+a#k /etc/'roup
248:. I E0 < K&K J
I print A1 | KsortK J
I nlines\\ J
4.F I print nlines J
--> a#k e!ample+
a#k L/X/ Iprint K8ot a commentKJL /etc/hosts
--> delete ever( 2nd field in file
a#k LIA2< KK printJL datafile > datafile+ne#
--> a#k avera'e/standard deviation pro'ram
!1 \< A1
!2 \< A1]A1
4.F I
!1 < !1/.,
!2 < !2/.,
si'ma < s5rt(!2 - !1]!1"
if (., > 1" std/err < si'ma/s5rt(., - 1"
print K.um)er of points < K .,
print K>ean < K !1
print K0tandard Feviation < K si'ma
print K0tandard 4rror < K std/err
Add new user
useradd -d /export/home/tester -m -s /usr/bin/bash tester
passwd tester
If Backspace key does not work:
stty intr
stty erase
stty echoe # set destructive backspace
Set Terminal from Console
TERM=vt100
export TERM
stty erase h !a"ter erase hit space then backspace to create the h
character# makes the backspace key work in vt100 terms$
usr/openwin/bin/resi%e !resi%es the termina&$
If Console Disconnect Results in ok> Prompt
send break
setenv ttya-i'nore-cd true
nvstore
'o
Network Info
netstat -rn # show current routes
netstat -rnv # show current routes and their masks
netstat -k # detai&ed device in"o !&ook "or inter"ace$
netstat -s # protoco& detai&
Disk Information
prtvtoc /dev/dsk/c1t0d0s0
du -ks ( ) sort -nr # shows si%e o" individua& directories
S !ersion
uname -a
Detailed "ardware Info
prtdia'
prtcon"
#iew $wait$ time% refres& e!ery ' sec
mpstat *
C&eck disk info% refres& e!ery ' sec
iostat -d * # serv shows disk service time in ms
iostat -xtc # read# write# cpu stats
"A system commands:
scswitch -% -h ema-site1b -' R+,+-ME.+/.E # switch "rom ema-a to ema-b
SS" Confi(uration
0pen /etc/ssh/sshd,con"i'
1ermitRoot2o'in yes
3114orwardin' yes
5&&owTcp4orwardin' yes
/etc/init6d/sshd stop
/etc/init6d/sshd start
)ount *SB Dri!e
To mount the drive# you have to "ind out the device name "or the 7-8
drive !e6'6 /dev/dsk/c9t0d0p0$# then:
mount -4 pc"s /dev/dsk/c9t0d0p0:c /mnt
Sin(le *ser )ode
boot cdrom -s
mount /dev/dsk/c1t0d0s0 /a ;--wi&& boot to /a dir
A+)
#6 to enter 520M
<conso&e< to exit
bootmode bootscript==boot disk1= ;-- use i" boot commands aren<t workin'
"rom 081 !ok prompt$
Tar
tar cv" "i&e6tar /etc/dir-to-tar
tar cv"h "i&es6tar /etc/dir-to-tar !to "o&&ow symbo&ic &inks$
tar tv" "i&e6tar !show the tab&e-o"-contents o" the tar "i&e$
Determine re,oot &istory
&ast reboot
Add new &ardware
touch /recon"i'ure !-o&aris &ooks "or /recon"i'ure at boot$
Ad-ust Pa(in( Be&a!ior
export 15+ER=&ess
man &ess !"or more in"o# &ess has more "eatures$