Thursday, February 19, 2004

Commonly Used Unix/Linux Tools and Commands

















































Browserlynx, mozilla, konqueror,
nautilus
Emailpine, mutt, kmail, gnus, balsa
Download(s)ftp, wget, kget, downloader for
X
Editorpico, vi, (x)emacs, ginf(html),
kite(latex), kate
Zipzip, unzip, gzip, zcat, bzip2,
tar
PS/PDFenscript, dvips, ps2pdf, pdf2ps,
a2ps, ps2epsi, xpdf, gs, gv, ggv
Image/Graphicxv, xfig, dia, gimp, gnuplot
Instant messengerlicq, amsn, gaim
Mutimediampg123, xmms, mplayer, toaster
Office suiteabiword, kword, koffice,
openoffice
IDEglade, motor, eclipse

















































































































































































































































































Command Command line
with arguments

Description

a2ps
% a2ps input -R -B
--right-footer='%s./%s#' -o output.ps

% a2ps -r --columns=1 -B -f10 --border=no -MLetter
--pretty-print=plain -o output.ps input
arguments: -r landscape (-R
for portrait), one column per page (default is 2), -B no
header , -f10 font size, --border=no no border, -MLetter
paper size to Letter, --pretty-print=plain print mode
turning off the highlights of keywords.
% a2ps input -2 -B
--right-footer='%s./%s#' ---footer='cenfooter'
-header='test' --cen='report' -o output.ps
more arguments: $Q = Page
$p./$p# (page number for this file), %Q = Page %p./%p#
(current page number), %s. (current sheet number), %s#
(total number of sheets), $s# (number of sheets of the
current file)
% a2ps $1 --columns=2
--pretty-print=$2 --font-size=8 --header='ID: 12345' -o
$3

% a2ps typescript -2 -B --right-footer='%s./%s#'
--footer='ID: 12345' --header='Asn 1' --cen='Captured
result' -o output.ps

% a2ps main.cpp -B -R --columns=1
--right-footer='%s./%s#' --left-footer='ID: 12345'
--header='Asn 1' --cen='main.cpp' -o main.ps
different output
format

ar
% ar rs liblprint.a
lprint1.o lprint2.o lprint3.o
creat a static library
with several object files
% ar -t
/usr/lib/libm.a
show the library object
dependency of libm.a
% ar -d liblprint.a
lprint3.o

% ar -s = ranlib
delete the module
awk % ls -aRl | awk '{sum =
sum + $5} END {print sum}'
sum up and print out
the file sizes

bzcat
% bzcat
prog-2.0.patch.bz2 | patch -p0
Unzip the bzip2 file
and do the patching
cat % cat file | tr -cd b |
wc -m
count the number of "b"
in the file
% cat id.pub | ssh
huang@csd.uwo.ca "(mkdir .ssh; cd .ssh; cat>>
auth)"

% cat file | ssh host "cat >> file"
ssh could be "rsh" or
"rlogin"
cb % cb -s test.cc >
test1.cc
indent code
according to K&R style (same as indent)
% cb -j test.cc put split lines back
together

chmod
% chmod -R 755
{zhu,wu,liang}/Asn1/docs/*

% chmod -R 755 [a-k]*/Asn2/*
change the
dir/subdir's permission

col
% man find | col -b
> find.txt
output a man page
into a plain text file

crypt
% crypt key <
plaintext > encrypted

% crypt key < encrypted > plaintext
Unix command,
Linux's crypt(encrypt) is a function call

diff
% diff -Nur
prog-1.0 prog-2.0 > prog-2.0.patch

% patch -p0 < prog-2.0.patch
Make a patch

dig
% dig
@ns1.uwo.ca genome1.beowulf.uwo.ca

%
dig -x
129.100.171.47

nslookup
find % find / -name
abc -print > result 2> errout

% find / -name abc -print 2>&1
1> logfile
B shell
% (find /
-name abc -print > result) >&
errout

% find / -name abc -print >&
logfile
C
shell
% find /
-type f \( -perm -2 -o -perm -20 \)
-exec ls -lg {} \; > files-results

% find / -type d \( -perm
u=rwx,g=rx,o=rx \) -exec ls -ldg {}
\; >dir-results
find the
files or directories with specific
permission
% find
[v-z]*/A*3/ -user wang -exec rm -f
{} \;
delete
all files created by user "wang" in
the directory between "v*" to "z*",
subdir of Asn3
% find
$HOME \( -name a.out -o -name '*.o'
\) -atime +7 -ok rm {} \;
remove
all files named a.out or *.o that
have not been accessed for a week,
need to confirm for each
execution
% find .
\( -type f -a -size -10k \)
-ok exec cp {} ~/tmp/ \;
copy
small size regular files to a
directory

% for i
in `find / -name *.[ch]`; do grep
-H jiffy $i; done


find
all files with defined string. -H
prints the filename for each
match

finger % finger
@hostname
show
users' info ( some versions need a
"*" before "@")
% finger
-f | awk '{print $1}

% finger -q -f | awk '{print
"User", $1, "is logged in on TTY:",
$2}'
print
out the login users with desired
format


gcc

% gcc
-o math math.c -lm

link
the shared libary
(libm.so)


% gcc
-o math math.c -lm
--static



static link. all code of libm.a
is merged into your distributed
executable

% gcc
-E test.c > test.i
turn
off compilation phase and display
the preprocess info
% gcc
-DBUFFERSIZE=1024
-D"max(A,B)=((A)>(B)?(A):(B))"
test.c

define the constant and
macro
grep %
grep -r string rc.d/
find
string in all files in rc.d
dir/subdir recursively, the same
as "-d"
% grep
-i '^\(.\).*\1$' file
all
lines whose first letter is the
same as the last one regardless
of the case (-i =-y)
gunzip %
gunzip [-q] < file.tar.gz |
tar xvf -
the
same as Linux's "tar zxvf
file.tar.gz"
indent %
indent -bad/-st/-kr/ test.c >
newformat.c

beautify the code with different
format as cb does
kill % kill
-9 -1
Kill
all processes in the login
machine
ls % ls
-aul

access tme
lsof % lsof
| nl

% lsof -u huang
list
all open files (by specified
user)
%
lsof -i -nP | grep ssh

% lsof -i :5000

% lsof -i :smtp

% lsof -i @hotmail.com

List all open files associated
with Internet connections
%
lsof /dev/cdrom

% lsof +D /tmp

% lsof `which sendmail`

% lsof -t `which
sendmail`

Who are using these
files?


netstat


% netstat -rn
routing
table

% netstat -alp
connection
statistics

nl

% nl -ba message.log | tail
-30 | grep error
print the
message having error in the
last 30 lines of the log
file
nm
% nm -a prog

% nm -s prog
list all the
symbols of the object
file
% nm -o
/lib/* /usr/lib/*
/usr/lib/*/*
/usr/local/lib/*
2>/dev/null | grep
'atoll'
search the
libraries for the
function
% nm -ng
prog
show
external symbols and
sorted by addresses

nohup
% nohup find
/ -name abc -print >
result 2>/dev/null
&
continue
finding after logout

ps
% ps
-efww
full format
(Linux)
% /usr/bin/ps
-axf
pstree plus
ps (Linux)

rcp
% rcp
brown:hb/\* .
the same as
"scp brown:hb/* .". rcp
needs .rhosts in remote
hosts:

snm.szptt.net.cn
huang

java huang

rusers


% rusers -l
hostname
show all
users in the host
% rusers
-a
show all
host names in the
network

sed
% cat file
| sed 's/^#/;/g' >
newfile
change
comments format (shell
to lisp)
% ls *htm |
sed 's/\(.*\)htm/mv
& \1html/' |
sh
change the
extension
% sed -e
's/\(\<[A-Za-z]*[aeiou][A-Za-z]*[aeiou][A-Za-z]*\>\)/(\1)/g'
file
surround
all words containing 2+
or vowels with (),
"tea"-->"(tea)"
(<> match
words)

sh
% sh -xv
shell_script
debug the
bsh script program
(csh: % csh -xv)

tar
% tar tvf
file.tar
show all
the files in a tar
file
% tar rvf
my.tar newdir
append
files in newdir to
my.tar
% tar uvf
my.tar mydir
update
my.tar with newly
updated files in
mydir
% tar cvf -
file | gzip >
file.tar.gz
the same
as linux's "tar cvfz
file.tar.gz file"
% (cd
~huang/target; tar -xvf
- .) | (cd
~huang/backup; tar -xvf
-)

% (cd ~/target; tar
cf - .) | rsh casky "cd
~/backup; tar xf -"
backup the
files in remote
machine
tr % tr -d
"\015" < input
> ouput
remove
the ugly ending char
in text files ftped
from windows to Unix,
the same as
"dos2unix"
% cat
a.txt | cat abc
| tr '[a-zA-Z]'
'[n-za-mN-ZA-M]' >
encrypted.txt

% cat
a-encrypted.txt | tr
'[a-zA-Z]'
'[n-za-mN-ZA-M]' >
decrypted.txt
the
easiest way of
encryption

uuencode
%
uuencode a.out key
> secret.out

% uudecode
secret.out
"key"
is a decode
label

wget
%
wget -r -l 4 -np
-N
http://www.abc.com

% wget -c -L
-nH
http://www.abc.com/big.zip

% wget
--passive-ftp
ftp://abc.com/d*/*.doc

download the
contents of the
website,
recursively (-r)
with depth 4 (-l
4), page
requisite mode
(-p), not ascend
the parent
directory (-np),
enable timestamp
(-N), continue
download the
interrupted file
(-c), only get
files from
relative links
(-L), disable
long header
(-nH).
%
wget -E -k -K
-p
http://www.abc.com

% wget -r
-H -l inf
--ignore-length
-p -e
robots=off
http://www.abc.com

% wget
--http-user=huang
--http-passwd=abc
--cache=off
--cookies=off
http://www/secret

html-extension
mode (-E) is
useful for asp
and cgi pages,
link-convert
(-k) and backup
the original
version (-K,
affects -N),
enable
span-host (-H),
ignore the
bogus
"Content-Length"
headers by CGIs
(--ignore-length),
turn off the
robots
mechanism(-e
)
%
wget
--save-cookies
cookies.txt
--post-data
'user=foo&password=*'
http://www.abc.com/auth.php

% wget
--load-cookies
cookies.txt
-p
http://www.abc.com/doc/article.php

llogin to the
server and
save the
cookie file (
done only
once), then
grab the
desired
pages

who

%who -u |
sort +0 -1
-u

display the
login users
without
repeat
names

%who -u |
cut -c1-10
| sort |
uniq -c |
grep -v " 1
"

display the
users
having more
than on
terminals

xterm

% xterm +ls
-sb
-rightbar
-sl 1000 -j
-title
"dreamer"
-fn
"*-courier-bold-r-*-140-*"
-b 5
-display
0:0 -bg
black -fg
green
-geometry
80x50+10+5
&



open an
xterm with
pure
subshell
(+ls) mode,
scrollbar
(-sb) with
1000 lines
(-sl) in
the right
side
(-rightbar),
jump
scrolling
(-j), font
defined
(-fn),
black
background
(-bg) and
green
foreground
(-fg), 80
characters
per line,
50 lines,
ordinate
(10, 5)
from
upper-left
corner.
( -10-5
means x
ordinate of
10 from the
right,
y ordinate
of 5 from
the
bottom)