who (who is on the system)
who -b (when was last reboot)
who -r (current run level)
w (who is doing what)
df -h (disk usage info in human readable form)
Unix commands
§cut
Cut out columns from a table or fields from each line of a file
•cut -c5
cut out at character 5
•cut -c1,5,10
cut out at chars 1, 5, 10
•cut -c1-10
inclusive from 1 to 10
•cut -c5-
to eol
•cut -d: -f1 /etc/password
use : as delimiter
cut at field 1
•cut -f1
default to -dTab
•sed -n l file
print tab as >
§paste
Concatenate lines of input files.
•paste files
Concatenate lines of input files.
•paste -d’+’ files
Use + instead of TAB to replace NEWLINE charactem
•paste -s file
Concatenate all lines of each file except the last line
§sed
•sed ‘s/unix/UNIX/’ file
replace 1st occurance
•sed ‘s/unix/UNIX/g’ file
replace all occurance
•who | sed ‘s/ .*$//’
del
•sed -n ‘1,2p’ file
print 1st 2 lines
•sed -n ‘/UNIX/p’ file
print all lines w/ UNIX
•sed ‘1,2d’ file
delete 2 lines
•sed ‘/UNIX/d’ file
delete UNIX
•sed -n ‘l’ file
tab as >
•Replace all occurrance of c:/Perl to /usr/perl in all perl scripts in current directory
for i in 'ls *.pl' do fileName='echo $i | awk -F"." { print $1 }' sed 's/c:\/Perl/\/usr\/perl/' $i > $fileName.new cp $fileName.new $fileName.pl done
§tr works on single char start inetd Patch manaqement Solaris: pkgadd -d linux: Enable root ssh References
•tr : ‘ ‘
colon to tab
•tr ‘[a-z]’ ‘[A-Z]’ to upper case
•tr -s ‘ ‘ ‘ ‘ squeeze out mult
•tr -d ‘ ‘ < file del all spaces
•tr '\012' ' ' change new line char to space. Same as
awk '{printf "%s ",$0}'
§grep
•grep pattern files
•grep -i ignore case
•grep -v inverse
•grep -l list file names only
•qrep -n show line number
§sort
•sort file
•sort -u remove dup lines
•sort -r reverse sort
•sort file -o sorted_file
•sort -n file sort as number
•sort +2n file skip 2 fields,sort num
•sort +2n -t: delimit by :
§uniq only works on consecutive
duplicate lines
•uniq file
•sort file | uniq sort,uniq
•sort /etc/password | uniq -d
list duplicate lines
•sort /etc/password | cut -f1 -d: | uniq -d find dup user id
•uniq -c count dups
§shift
•left shift positional parameters by 1
•shift 3 left shift by 3
restart inetd:
ps -ef | qrep inetd --> qet psid
kill -HUP
/etc/init.d/inetsvc start
patchadd
patchrm
showrev -p
pkgparam
pkgrm SMCgcc
pkginfo
rpm -iv somefile.rpm
rpm -qa | grep binutils
rpm -Uvh –force –nodeps binutils-2.11.90.0.8-13.i386.rpm
* Edit /etc/ssh/sshd_config and set
PermitRootLogin yes
*Restart network servicessvcadm restart svc:/network/ssh:default
http://www.sun.com/bigadmin/shellme/
unixtoolbox
linux-unix-commands-cheat-sheets