2008-04-05

Linux cmd options

# general references
http://blog.lxpages.com/ultimate_linux.html
http://www.cpqlinux.com


apt-get

apt-cache search package

apt-get update
apt-get install pack_list
apt-get remove pack_list


at

at now -f ~/bin/test.sh


basename

Note:
1. basename can also strip suffix
2. basename may give you ./ or ../, try `cd $(basename file); pwd` instead to get the absolute path

EXAMPLES

basename /usr/bin/sort # output "sort"
basename include/stdio.h .h # output "stdio"


bc

pi=`echo "scale=10; 4*a(1)" | bc -l`


cat

-A --show-all, -vET

-b --number-nonblank
-n --number
-s --squeeze-blank

-e --show-ends: $
-E --show-ends: $
-T --show-tabs: ^I
-v --show-nonprinting: ^ for CTRL, M- for ALT

# 显示非打印字符, TAB, End-of-line
cat -A exam.txt

# 显示系统信息
cat /proc/cpuinfo
cat /proc/meminfo
cat /proc/version
cat /proc/partitions
cat /etc/debian-release

cat ;gt awkscr.tmp ;lt;lt EOF
BEGIN { print "Hello" }
EOF


chown

chown -R user:group path/dir


comm

-1 suppress lines unique to FILE1
-2 suppress lines unique to FILE2
-3 suppress lines that appear in both files

# 显示在data1 data2中都存在的行
comm -12 data1 data2


cpio & rpm2cpio

http://www.brandonhutchinson.com/cpio_command.html


crontab

crontab [-u user] file
-e edit
-l list
-r remove

# script format
minute hour day month week(0=Sunday) command
# example
0,30 18-23 * * * /usr/bin/dbcheck.sh


date

date option +%format

date +%d-%m-%y # 10-03-06

date +%y%m%d-%H%M # 071003-1555



dd
copy & convert raw data

# dump the image from the cdrom
dd if=/dev/cdrom of=image.iso bs=2k

cf.
http://en.wikipedia.org/wiki/Dd_(Unix)
http://www.linuxquestions.org/questions/linux-newbie-8/learn-the-dd-command-362506/
http://www.codecoffee.com/tipsforlinux/articles/036.html


dpkg

dpkg -i package.deb # install
dpkg -r package # remove


echo

-n do not output \n
-e enable \n, \t


expect

# example: 用expect登录,并根据网络的速度调整timeout

#!/usr/bin/expect
set timeout 3
set ADDR user@123.1.1.1
spawn ssh $ADDR
#spawn ssh [lindex $argv 0]
#set PASSWD [lindex $argv 1]
set PASSWD XXXX
expect "password:"
send "$PASSWD\n"
set timeout 3
expect "$"
send "\r"
expect "$"
interact


font: xdpyinfo, fc

# dot per inch
xdpyinfo | grep dot
# resolution
xdpyinfo | grep dimension

# font for monospace
fc-match mono


lpr

# Double-sided long edge
lpr -Plp104 -o Duplex=DuplexNoTumble file.ps

# Double-sided short edge
lpr -Plp104 -o Duplex=DuplexTumble file.ps

# Single-sided
lpr -Plp104 -o Duplex=None file.ps


lvm

lvm --help
vgchange --help
vgrename --help

# rename the old Volume group to some name besides VolGroup00
vgchange -a y VolumeGroup00
vgrename VolGroup00 VolGroup11

# mount
mkdir /home/oldstuff
mount /dev/mapper/VolGroup11-LogVoll01 /home/oldstuff

# data transfer
cp /home/oldstuff/home/username/* -t /home/username/from_old

# term
http://wiki.linuxquestions.org/wiki/LVM
LVM Logical Volume Manager
PV physical volume
PE physical extents
VG volume group
LV logical volume


mkdir

-m --mode=MODE
-p --parents, no error if existing, make parent dir as needed

# 建目录 ~/work ~/work/tmp, 权限为 755
mkdir -p -m 755 ~/work/tmp


mount & umount

# windows folder
mount -t smbfs -o username=xxx,password=xxx //hostname/dir /mnt/tmp

# non-root
/etc/fstab
/dev/sbpcd /mnt/cdrom iso9660 user,noauto,ro

% mount /mnt/cdrom
% umount /mnt/cdrom

# check if device is busy
% fuser -v /mnt/cdrom

cf.
http://tldp.org/HOWTO/CDROM-HOWTO/x1186.html


ping

# no response: 防火墙把icmp回播禁掉了


ps

********* simple selection ********* ********* selection by list *********
-A all processes -C by command name
-N negate selection -G by real group ID (supports names)
-a all w/ tty except session leaders -U by real user ID (supports names)
-d all except session leaders -g by session leader OR by group name
-e all processes -p by process ID
T all processes on this terminal -s processes in the sessions given
a all w/ tty, including other users -t by tty
g all, even group leaders! -u by effective user ID (supports names)
r only running processes U processes for specified users
x processes w/o controlling ttys t by tty

*********** output format ********** *********** long options ***********
-o,o user-defined -f full --Group --User --pid --cols --ppid
-j,j job control s signal --group --user --sid --rows --info
-O,O preloaded -o v virtual memory --cumulative --format --deselect
-l,l long u user-oriented --sort --tty --forest --version
-F extra full X registers --heading --no-heading --context

********* misc options *********
-V,V show version L list format codes f ASCII art forest
-m,m,-L,-T,H threads S children in sum -y change -l format
-M,Z security data c true command name -c scheduling class
-w,w wide output n numeric WCHAN,UID -H process hierarchy


screen

http://www.ibm.com/developerworks/cn/linux/l-cn-screen/index.html


trap

trap "echo 'here'" INT TERM

# 忽略信号
trap "" HUP # nohup

# 重置信号
trap - INT TERM


zip & unzip

unzip
-x xfile(s), An optional list of archive members to be excluded from processing.
-d exdir, an optional directory to which to extract files

-f freshen existing files, create none
-l list archive files (short format).
-j junk paths, do not make directories
-n never overwrite existing files
-o overwrite files without prompting
-p extract fils to pipe
-v verbose print info
-z display archive comment

# unzip multiple files
unzip '*.zip'

# zip a folder
zip -r [zip] [dir]
# extension is required in the following case
zip -r 10.1.zip 10.1

# 7zip
7z x -y *.zip
7z x -y *.rar

No comments: