2008年7月7日星期一

我常用的LINUX命令(转)

我常用的LINUX命令
--转自CSDN上 jerryfleming 的 Blog

############################################################################
#
# Useful Linux Commands
# ----------------------------------------------------------------------
# Jerry Fleming, 2004-09-13
#
############################################################################

# show system load in ascii art
tload
# simple watcher
swatch
# send process to bg like C-Z does
suspend
# execute a command by someone else
sudo
# change to another user(default: super user)
su
# change to another group
newgrp
# process information
procinfo
#show uid and gid
id
# gnu interactive tools process status
gitps

# tar ball size restricted
tar cvzpf - mytarfile.tar.gz | split -d -b 500m
cat x* > mytarfile.tar.gz

# save man page and info to file
man tcsh | col -b > tcsh.txt
info tcsh -o tcsh.txt -s

# join two files
cat file1 file2 | sort | uniq # (unique) lines in both files
cat file1 file2 | sort | uniq -d # (duplicated) lines in both files
cat file1 file2 | sort | uniq -u # lines only in one file

# show system info
cat /proc/cpuinfo # CPU (i.e. vendor, Mhz, flags like mmx)
cat /proc/interrupts # interruptions
cat /proc/ioports # ioports
cat /proc/meminfo # mem used, free, swap size
cat /proc/partitions # all partitions on all devices
cat /proc/pci # PCI devices
cat /proc/swaps # all swaps
cat /proc/version # equal to: uname -r
uname -a

# shwo (and kill) processes using filename
fuser filename
fuser -k filename

# show netbios name of a host
nbtscan -r 192.168.1.0/24
# show ip of host with netbios name
nmblookup 192.168.0.1
# send a message to win host (Messenger service on NT and WinPopup on '98)
smbclient -M NETBIOS
# useful on linux and windows
netstat -nap


# who am i
echo $LOGNAME
echo $USER
id
whoami
who am i
logname

# change properties of a file
chattr
setfacl

# show the size of a dir
du -sh dirname

# reh hat version info
cat /proc/version
cat /etc/redhat-release
cat /etc/issue

# what is running on port 22
lsof -i :22

# rename a host
/etc/sysconfig/network-scripts/ifcfg-eth0
/etc/hosts
/etc/sysconfig/network

# show the size of pwd
du --max-depth=0 -h
# calculate the sum of first column in myfile
gawk 'BEGIN{sum=0;} sum = sum+ $1; END{print sum;}' myfile

# mysqldump synopsis
mysqldump -Q -p --opt -B aiqing avo geofuture leidi17 lizi17 phpmyadmin qiti swy 新COM > dbdump
mysqldump -Q -p --opt -B fiveone > fiveonedump
mysqldump -Q -p --opt -B newcom > newcomdump
mysqldump -Q -p --opt -B mysql > mysqldump
# update a database from update log files
ls -1 -t -r file_name.[0-9]* | xargs cat | mysql
# update a MySQL server from the binary log
mysqlbinlog log-file | mysql -h server_name
# mysql charset and collation
mysql> SET PASSWORD FOR 'root'@'localhost' = OLD_PASSWORD('jerry');
query("SET character_set_results = big5") ;
query("SET collation_connection = big5_chinese_ci ");
query("SET character_set_client = big5 ");
query("SET character_set_connection = big5 ");
mysql> SET character-set-client = x;
mysql> SET character-set-results = x;
mysql> SET character-set-connection = x;


# to encode one script do:
php -q encoder.php -f input.php -o output.php

# to encode directory do:
php -q encoder.php -rcf input_dir -o output_dir

# eigth modes of operation for tar
create extract list append update concatenate delete compare

# copy contents of a dir from one disk to another
cd sourcedir; tar -cf - . | (cd targetdir; tar -xf -)

# write raw data of kernel image to a floppy
dd if=babylinux.img of=/dev/fd0
cat babylinux.img >/dev/fd0

# set default editor ~/.muttrc
set editor="vi -c ':0;/^$'"

# set bash command line to vi mode
set -o vi

# set vim macros
:map X
:set ww=h,l,b,s
inoremap :w %
noremap :w %
map ^F
set ww=h,l,b,s
colorscheme murphy
noremap :!python %
inoremap ( ()i
inoremap [ []i
inoremap { {}i
inoremap ' ''i
inoremap " ""i
inoremap $_S $_SERVER['']hi
inoremap $_G $_GET['']hi
inoremap $_P $_POST['']hi
inoremap $_R $_REQUEST['']hi
inoremap $_C $_COOKIE['']hi
# change multiline text with the (visually) selected in vim
vlhy:%s??\=getreg('"')?g
# change absolute path to be relatvie w/ vim
%s/(href\=|src\=)\"([^#/(mail|http)])/\1="\2/gc


# start chinese input method IME
export LC_ALL=zh_CN.GB2312
export XMODIFIERS=@im=Chinput
chinput &
# change default IME
im-switch -m xim

# start X server
X&
# start X term on display 0
xauth add :0 . `mcookie`
xterm -display :0 &

# mount an iso file as virtual cdrom
mount -o iocharset=gb2312
mount -t msdos
mount -t iso9660 -o loop ./my.iso /mnt/iso
# mount and display Unicode file names
mount -t iso9660 -o loop codepage=cp950 iocharset=cp950 ./my.iso /mnt/iso
# mount shared dir over samba
mount.smb //host/sharename /mnt/directory/ -o username=guest,password=xxxxx,fmask=0,dmask=0,rw
mount -t smbfs -o username=guest //hostname/sharefile /path/to

# fetch all mails and do not delete the old ones from a remote mail server
fetchmail -u shaojiachao@5117.com -ak mail.5117.com

# convert image
convert -draw "image Over 10,20 0,0 logo.gif" 256.gif 256.jpg

# make a mirror of 8617.cn
wget -F --tries=30 -nd -P8617 -E -k -m -p -D www.8617.cn http://www.8617.cn

# change the color of command line (add to .bashrc)
PS1="\[\e[33;41m\][\u@devserver \w]\[\e[32;40m\]\[\e[01m\]#\[\e[0m\]"
# also works, but first command line maybe shortened to 70% of the screen width
PS1="\e[33;41m[\u@ \w]\e[32;40m\e[01m#\e[0m"

# pack a whole dir
tar cvfz xx.tar.gz ./* --exclude=dir1 --exclude=dir2
tar cvf - ./* | gzip -qc > back.tgz

# restore mysql db from a dump file
mysql -p <>

# decoding error for chinese in Linux 8.0
export LC_ALL=en_US
export LANG=C

# control vsftpd
/etc/rc.d/init.d/xinetd restart

# a simple editor like WPS driven by hot keys ( ^KH for help)
joe

# Midnight Commander, like Norton Commander in DOS
# hot keys at screen bottom of the (diplayed as 1, 2 etc) stards for F1, F2 etc
mc

# a powerful ftp client, supporting wild cat and download of a whole dir
# anonymous login:
ncftp xxx.xxx.xxx.xxx

# a ftp tool with bash like job control, command completion and more
lftp

# an powerful email client
pine

# get version info of kernel
uname -a
guname # in X

# screenshot for text terminal
cat /dev/vcsX >screenshot # X stands for the no. of terminal (?)
script screen.log # exit to stop

# run a command immune to hangups, with output to a non-tty
nohup command &

# make the shell a login shell with su
su - root

# print the name of the terminal
fgconsole
tty

# display brief info on a bash built-in command
help command

w
who
rwho -a
whoami
ftpwho

last
lastb

# show the amount of time since the last reboot
uptime

# check what distribution you are using
# (displayed on login, therefore it functions like /etc/motd )
cat /etc/issue

# (mnemonic: disk free) print disk info about all the filesystems
df -h # in human-readable form
# (mnemonic: disk usage) print detailed disk usage
du / -bh | more # for each subdirectory under PWD in human legible form

# show cpu info stored in /proc/cpu
cat /proc/cpuinfo
# list the interrupts in use (maybe useful before setting up new hardware)
cat /proc/interrupts
# Linux version and other info
cat /proc/version
# show the types of filesystems currently in use
cat /proc/filesystems
# show the setup of printers
cat /etc/printcap |more

# show the current user environment (in full)
set|more

# print kernel messages
# (so-called kernel ring buffer in /var/log/dmesg after bootup)
dmesg | less

# display all the configurable Linux kernel parameters.
sysctl -a |more

# lock a local (text mode) terminal.
vlock

# html editor in X ternimal
bluefish

# spell check an ASCII text file
# AbiWord, WordPerfect, StarOffice come with as-you-type spellchecking
aspell
ispell filename

# look up the dictionary on your system (/usr/share/dict/words) for thermo*
look thermo

which
whereis
whatis

# start another X-window session on the display 1 (default opened on display 0)
startx -- :1 &

# receive files using the Zmodem, Ymodem, or Xmodem protocol
rx

unarj e filename.arj
lha e filename.lha
uudecode -o outputfile filename
ar -x my_archive.a file1 file2

# run any command when the system load is low, CTRL-D to end
# (if logout, the process will keep running and the result will be emailed)
batch

# kill programs by name
killall program_name

# check and control the printers (? to see the list of available commands)
lpc
# show the content of the printer queue
lpq
# remove a printing job
lprm job_number

# execute my_command repeatedly at 60-second intervals (default to 2 seconds)
watch -n 60 my_command

linuxconf
netconf # a subset of linuxconf
mouseconf

# automatically determines and configures hardware
# (disable it if having mysterious problems with your mouse)
kudzu

# set the timezone for your system.
# UTC, Coordinated Universal Time, once called GMT, Greenwich Mean Time
# timestamps of files are always in UTC and displayed locally with time zone
timeconfig

# set linux system date and time to 2000-12-31 23:57
date 123123572000
# set your computer hardware clock from the current linux system time
setclock

# list files opened on your system
lsof

# tune up your parallel ports
tunelp

ntsysv
tksysv # X-based
# a tool to check/enable/disable system services
/sbin/chkconfig --level 123456 kudzu off
# to list all the services started/stopped under all runlevels, I use:
chkconfig --list | more
service --status-all
service wu-ftpd start
service smb restart

# check and fix the symbolic links
symlinks -r -cds /

# re-create the bindings and the cache for the loader of dynamic libraries ld
# usually after an installation (automatically done in bootup)
ldconfig

# (mnemonic: make node) manually create a device file
mknod /dev/fd0 b 2 0
# restore the "audio" device that somehow screwed up
/dev/MAKEDEV audio

# hard drive partitioning utility, menu-based, easier than fdisk
cfdisk /dev/hda

# list the partition tables (including extended partitions) for all drives
sfdisk -l -x |more

# a partition manipulation Linux (ext2), and DOS (FAT and FAT32)
# (creation, destroying, moving, copying, shrinking, and extending)
parted /dev/hda

# perform a low-level formatting of a floppy, high density
# then make a Linux filesystem (-t ext2), checking/marking bad blocks (-c )
# making the filesystem is an equivalent to the high-level formatting
fdformat /dev/fd0H1440 # default 1440 kB, see ls /dev/fd0
mkfs -c -t ext2 /dev/fd0

# check a high-density floppy for bad blocks, does not modify the floppy
badblocks /dev/fd01440 1440
# umount it so that the data is not erased!
umount /dev/hda8
badblocks -n /dev/hda8
# mount back
mount /dev/hda8
# marks badblock
e2fsck -c /dev/hda8

init 1 # switch linux to single user mode, same as below
linux sigle # for grub prompt
# check and repair a filesystem (in runlevel 1)
fsck -t ext2 /dev/hda2

# adjust the tuneable parameter of an ext2 filesystem to ext3
tune2fs -j /dev/hda2

# (mnemonic: data duplicator, like DISKCOPY for DOS)
# create an image of a floppy to floppy_image in pwd
dd if=/dev/fd0H1440 of=floppy_image
# copy floppy_image to another floppy disk
dd if=floppy_image of=/dev/fd0H1440

mkbootdisk --device /dev/fd0 2.4.2-3

userdel user_name
groupadd group_name
chgrp friends my_file
chmod g=rw,o= my_file
usermod
groupmod
userconf

# change the your information as displayed by finger
# (mnemonic: change full name)
chfn

# set the password expiry for login_name (mnemonic: change age)
chage -M 100 login_name

quota username
setquota username
quotaon /dev/hda
quotaoff /dev/hda

# run command with su
sudo /sbin/shutdown -h now

# verify the integrity of the password and group files.
pwck
grpck

rpm -ivh package_name-version.platform.rpm

route -n
host host_to_find
nslookup host_to_find
dig ip_to_find
traceroute host_to_trace
mtr host_to_trace

# status of a networked MS Windows host (with an NetBIOS name
nmblookup -A ip_address # like nbtstat for DOS

echo 1 > /proc/sys/net/ipv4/ip_forward
ipfwadm-wrapper -F -p deny
ipfwadm-wrapper -F -a m -S xxx.xxx.xxx.0/24 -D 0.0.0.0/0
ipchains -L
iptables -L
ifconfig
netstat | more

nmap ip_number

# eject or close other removable media, defaults to cdrom
eject -vn -t /dev/sda4

# read the content of a file for you
festival --tts my_file.txt

# give me a description of an image file my_picture,
# format, type, class, size in pixels, number of colours, size in bytes, etc
identify -verbose my_picture

# restore a screwed-up terminal to default (remove funny chars after cat)
reset
# reboot

# scroll terminal output up/down


# change to the previous/next X-server resolution
<->
<+>
# kill the window I am going to click

# kill the current X-windows server

# send [End-of-File] to the current process or log out
d
# stop the transfer to the terminal.
s
# resume the transfer to the terminal (when the terminal stops responding)
q
# send the current process to the background.
z
# walk through windows


# walk through desktops


# show the table of processes, kill any or send other signals to them

# access the K-menu, equivalent to MS Windows Start menu

# emulate the mouse using the arrow keys on the keyboard

# drag (any part of) a window to move it

# take a snapshot of the current window into the clipboard

# take a snapshot of the entire desktop into the clipboard

# lock the desktop

# toggle hide/show the desktop
# (great to hide the Solitaire game when your boss walks in)

# kernel level key combinations
# meant for debugging purposes and in an emergency (mostly developers)

# enabled/disabled by setting the relevant kernel variable to 1/0
echo "1" > /proc/sys/kernel/sysrq
# kill all processes, including X, known as Secure Access Key SAK

# send the TERM signal to all running processes except init, exit after confirm

# send KILL signal to all processes except init (powerful than
# but some process may exit abnormally)

# send the KILL signal to all processes, including init

# run an emergency sync (cache write) on all mounted filesystems
# (to prevent data loss)

# remount all mounted filesystems as read-only (like ,
# but, if successful, fsck won't check all filesystems after reboot)

# turn off keyboard raw mode
# (useful when X session hangs: afterward, )

# reboot immediately without syncing or unmounting your disks

# shut the system off

# dump the current registers and flags to your console


# dump a list of current tasks and their information to your console

# dump memory info to your console

# set the console log level
SysRq>
# display help
# also, any other unsupported

2008年7月6日星期日

一些快捷键定义,xfce一键关机等问题。

用xmodmap -pm可以查看各个控制键有lock, control mod1-mod4等这样的值,
我需要更改control键的定义,去掉没用的capslock键,那么我需要首先知道capslock的键值
可以用xev命令查看键盘的按键对应的键值.同样我可以更改win键,使它成为我的meta键。然后把要更改的键值写入~/.Xmodmap中,我的如下.我还定义了power键,在xfce的键盘快捷键中定义power为命令poweroff的快捷键,这样就实现了一键关机,我还定义了一键重启为wakeup键.
把小键盘的/*-分别定义为静音,音量减少,音量增加。

我的~/.inptrc的内容
"\e":"^[" #define escape
"\eOP":"emacs\n" #f1 start emacs
"\eOQ":"mplayer -zoom -xy 1024 -fs -quiet " #f2 start mplayer with fullscreen
#"\eOR":"/home/wayy/Opera/bin/opera\n" #f3 start opera
"\eOS":"firefox\n"#f4 start firefox

我的~/.Xmodmap的内容
clear mod4
clear mod3
keycode 115 = Meta_L Super_L
keycode 116 = Meta_R Super_R
add mod4 = Super_L Super_R
keycode 222 = XF86PowerOff
keycode 223 = XF86Sleep
keycode 227 = XF86WakeUp
keycode 112 = XF86AudioMute
keycode 63 = XF86AudioLowerVolume
keycode 82 = XF86AudioRaiseVolume
clear lock
clear mod2
remove control = Control_L
keycode 66 = Control_L
keycode 86 = Caps_Lock
keycode 77 = Num_Lock Pointer_EnableKeys
keycode 90 = F20
add lock = Caps_Lock
add control = Control_L
add mod2 = Num_Lock

2008年6月29日星期日

让emacs变成字典

第一步[root@localhost ~]# yum install dictd
第二步. 编写配置文件和下载字典数据库
现在本地dictd server还不能工作,你必须写两个配置文件dictd.conf和dict.conf(存储到/etc/目录下)他们的内容如下:
dictd.conf:

access {allow localhost allow *}
database Web1913 {data "/usr/share/dictd/web1913.dict.dz"
index "/usr/share/dictd/web1913.index"}
database wn {data "/usr/share/dictd/wn.dict.dz"
index "/usr/share/dictd/wn.index"}
~
上面的字典可以到ftp://ftp.dict.org/dict/pre/下载
dict.conf:
server localhost
第三步 [root@localhost ~]# /etc/init.d/dictd start
接下来:
你可以
[root@localhost ~]# dict word
查找到单词了吧,恭喜你。
然后编写
;;;;;辞典
(autoload 'dictionary-search "dictionary"
"Ask for a word and search it in all dictionaries" t)
(autoload 'dictionary-match-words "dictionary"
"Ask for a word and search all matching words in the dictionaries" t)
(autoload 'dictionary-lookup-definition "dictionary"
"Unconditionally lookup the word at point." t)
(autoload 'dictionary "dictionary"
"Create a new dictionary buffer" t)
(autoload 'dictionary-mouse-popup-matching-words "dictionary"
"Display entries matching the word at the cursor" t)
(autoload 'dictionary-popup-matching-words "dictionary"
"Display entries matching the word at the point" t)
(autoload 'dictionary-tooltip-mode "dictionary"
"Display tooltips for the current word" t)
(autoload 'global-dictionary-tooltip-mode "dictionary"
"Enable/disable dictionary-tooltip-mode for all buffers" t)

(global-set-key [mouse-3] 'dictionary-mouse-popup-matching-words)
(global-set-key [(control c)(d)] 'dictionary-lookup-definition)
(global-set-key [(control c)(s)] 'dictionary-search)
(global-set-key [(control c)(m)] 'dictionary-match-words)

;; choose a dictionary server
(setq dictionary-server "localhost")

;; for dictionary tooltip mode
;; choose the dictionary: "wn" for WordNet
;; "web1913" for Webster's Revised Unabridged Dictionary(1913)
;; so on
(setq dictionary-tooltip-dictionary "wn")
(global-dictionary-tooltip-mode t)
;(dictionary-tooltip-mode t)
添加到你的.emacs之中
重启emacs 光标放在某一个单词上C-c d 就可以查 字典了

emacs short cut

xmodmap -pke查看键盘映射
xev捕捉键盘或者鼠标动作,
~/.Xmodmap 做键盘映射
或者用命令
xmodmap -e "keysym Super_L = Meta_L Super_L"
xmodmap -e "keysym Super_R = Meta_R Super_R"
这样可以把win键变成meta
键盘宏很好用,我定义f7为注释一行,即前面加%
  • `C-x (’ – start defining a keyboard macro
  • `C-x )’ – stop defining the keyboard macro

And here is how to execute a keyboard macro you’ve defined:

  • ‘C-x e’ – execute the keyboard macro
M-x name-last-kbd-macro – Name the last-defined keyboard macro
M-x insert-kbd-macro – Insert a named keyboard macro into your initialization file

参见 http://www.emacswiki.org/cgi-bin/wiki/KeyboardMacros

Emacs快捷键
这样我不会有meta-tab和窗口管理器冲突的事情了,输入法的快捷键也被我改了,C-S-F9改为输入法
control-space 就是默认的做标记的命令
GNU Emacs

1. M-! 执行shell命令
2. 直接在终端中运行emacs /emacs -nw/
3. C-X 表示按住CTRL键, 然后按X, 再把CTRL, X一起放开.
4. M-X 等于先按 ESC键, 接著按 X键.
5. M-X 等于alt键.
6. C-X或 M-X的X没有大小写分别.
7. 超过两个以上的按键命令, Emacs会在萤幕最下面一行显示你按过什么.这一
行叫作mini buffer
8. 结束Emacs按 C-x C-c
9. 取消执行 C-g
10. C-p 向上移 (previous line)
11. C-n 向下移(next line)
12. C-f 向右移 (forward)
13. C-b 向左移 (backward)
14. C-v 下一页(view next screen)
15. M-v 上一页
16. C-L 重画萤幕
17. M-f 向前跳一个字(word)
18. M-b 往后跳一个字(word)
19. C-a 移到行头
20. C-e 移到行尾
21. M-a 移到句首 (M-a 到上一个句点后面,一个句子的起头.)
22. M-e 移到句尾 (M-e 到句点后面)
23. M-< 移到档头 24. M-> 移到档尾
25. C-d 删除游标目前指的后面的字
26. DEL 删除游标目前指的前面的字 (Delete键)
27. M-DEL 往回删一个字(word)
28. M-d 往前删 (游标后面)
29. C-k 删至行尾 (kill)
30. M-k 删到一句子结尾(删到句点) (kill)
31. C-x u 撤消操作
32. C-_ 也是撤消操作
33. C-k 剪切 (kill)
34. M-k 剪切 (kill)
35. 剪切一段文字的方法: 将光标移到想要剪切的文字段开头, 用 C-@ (或
C-SPC )设标记( Mark set ), 将光标移到想要剪切的文字段末尾, 用 M-w
剪掉那段文字.
36. C-y 粘贴 (yank) , kill & yank 就是 cut & paste的意思.
37. C-x C-f 打开文件(可以用tab 或SPC键自动补全文件名)
38. C-x C-s 保存文件
39. C-x s 保存所有的文件
40. C-x i 插入文件(把另外的档案的内容读入目前编辑区内)
41. C-x 0 关掉目前的视窗
42. C-x 1 会让目前的视窗占满整个萤幕 (One Window), 取消/关掉其他的视窗.
43. C-x o 跳到另一个视窗
44. C-x 2 把目前的视窗切成两个 (水平分割)
45. C-x 3 (垂直分割)
46. C-x 4 是一串与视窗有关的指令.
47. C-x 5 则是扩展到X的视窗, 称为frame.
48. C-x 5 2 就是再开另一个X视窗 (frame).
49. C-x C-b 看目前有那些buffer (buffer就是emacs放开起的档案的地方).
50. C-x b 然后在minibuffer输入buffer的名字, 可以切换编辑buffer, TAB键
也有作用. 有些内部的buffer (就是没有档案的buffer), 是用*开头和结
束, 这个也要打, 如*scratch*
51. 按 M-x 之后就可以打一个Emacs命令来执行
52. C-x C-c 就是结束Emacs,比较常用的是C-z
53. C-z 把Emacs暂停, 回到命令列. 当你下次再需要编辑时, 打fg %emacs 或
者 fg 就可以把Emacs唤醒. 在X下, C-z 会把emacs缩成icon.