一、 Fedora系統配置
- 1. 【設置網卡IP】
步驟如下:
1) 用root用戶登陸,打開/etc/sysconfig/network-scripts/ifcfg-eth0文件
注意:打開的文件要根據網卡來設置,如:網卡eth1的配置文件就是ifcfg-eth1。
2) 設置以下內容:
DEVICE=eth0
BOOTPROTO=static
IPADDR=10.128.32.36
NETMASK=255.0.0.0
ONBOOT=yes
GATEWAY=10.128.32.102
說明:網卡GATEWAY不一定要設置在這個網卡配置文件中,也可以配置到/etc/sysconfig/network文件中,如下所示:
NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=localhost.localdomain
GATEWAY=10.128.32.102
3) 重啟network服務
[root@localhost:/etc/sysconfig]# service network restart
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]
- 2. 【啟動telnet服務】
telnet服務是由xinetd(擴展的網絡守護進程服務程序)守護的,所以很多配置都是在xinetd下進行。具體步驟如下:
1) 檢測telnet、telnet-server的rpm包是否安裝
[root@localhost:/etc/sysconfig]# rpm -qa | grep telnet
telnet-0.17-37
telnet-server-0.17-37
主要看telnet-server有沒有安裝,如果沒有要先把telnet-server安裝起來(具體安裝方法略)。
2) 修改telnet服務配置文件
Fedora默認是不開通telnet服務的,所以需要手動配置開啟:
[root@localhost:/etc/sysconfig]# vi /etc/xinetd.d/telnet
service telnet
{
flags = REUSE
socket_type = stream
wait = no
user = root
server = /usr/sbin/in.telnetd
log_on_failure += USERID
disable = yes
}
將disable項屏蔽或者改為no:
disable = no
3) 修改Fedora下另一個telnet配置文件
對於Red-Hat系統,修改到telnet文件就可以了,但是Fedora對權限的管理比Red-Hat嚴格,還需要修改同一個目錄下的krb5-telnet,不然客戶端會鑒權不通過而無法連接。
[root@localhost:/etc/xinetd.d]# ls *telnet*
ekrb5-telnet krb5-telnet telnet
[root@localhost:/etc/xinetd.d]# vi krb5-telnet
service telnet
{
flags = REUSE
socket_type = stream
wait = no
user = root
server = /usr/kerberos/sbin/telnetd
log_on_failure += USERID
disable = no
}
將disable項屏蔽或者改為no:
disable = no
注意:在權限和鑒權方面,Fedora和Red-Hat一樣,都要讓防火牆允許telnet連接。一般,可以直接關閉防火牆,否則就必須用setup工具配置一下。
4) 重新啟動xinetd守護進程
[root@localhost:/etc/xinetd.d]# service xinetd restart
Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]
- 3. 【啟動FTP服務】
FTP守護進程是vsftpd,開啟步驟如下:
1) 檢測ftp、lftp的rpm包是否安裝
[root@localhost:/etc/xinetd.d]# rpm -qa | grep ftp
gftp-2.0.18-3.2.2
lftp-3.5.1-2.fc6
vsftpd-2.0.5-8
tftp-server-0.42-3.1
ftp-0.17-33.fc6
tftp-0.42-3.1
2) 配置開啟ftp服務
運行setup,在system service中選中vsftpd按空格選中,然后quit。
3) 關閉SeLinux的安全設置
和Red-Hat不同,Fedora存在一個SELinux的安全機制管理,需要撤銷SELinux對ftp的安全設置,FTP才能正常登陸,不然會報“500 OOPS: cannot change directory”的錯誤。執行下面的語句即可:
[root@localhost:/etc/xinetd.d]# setsebool ftpd_disable_trans 1
注意:一旦重啟該命令就會失效,所以最好的辦法是在X界面下,點擊菜單“System”à“Administration”à“Security Level and Firewall”,將選項SELinux設置為“Disable”,然后重啟系統,就可以保持這個設置了。
4)重啟FTP服務
[root@localhost:/etc/xinetd.d]# service vsftpd restart
Shutting down vsftpd: [ OK ]
Starting vsftpd for vsftpd: [ OK ]
- 4. 【設置開機自動執行】
設置方法如下:
1)用root用戶登陸
2)vi /etc/rc.local
3)添加要開機執行的語句,如果是一個腳本文件,注意要絕對路徑
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
setsebool ftpd_disable_trans 1
service vsftpd restart
- 5. 【設置自動關機】
自動關機可以在crontab中設置。假設希望每天23::50關機,設置方法如下:
1)用root登陸
2)vi /etc/crontab
3)在文件最后添加以下語句:
50 23 * * * root shutdown -h now
- 6. 【設置允許root登陸telnet】
設置方法如下:
1)用root登陸
2)vi /etc/pam.d/login
3)注釋該文件第一行內容:
#%PAM-1.0
#auth required /lib/security/pam_securetty.so
auth required /lib/security/pam_stack.so service=system-auth
auth required /lib/security/pam_nologin.so
account required /lib/security/pam_stack.so service=system-auth
password required /lib/security/pam_stack.so service=system-auth
session required /lib/security/pam_stack.so service=system-auth
session optional /lib/security/pam_console.so
- 7. 【設置允許root登陸ftp】
普通方式下,如果/etc/vsftpd/vsftpd.conf文件中有如下內容:
userlist_enable=YES
userlist_file=/etc/vsftpd.user_list
pam_service_name=vsftpd
只需在/etc/vsftpd/user_list和/etc/vsftpd/ftpuser文件中刪除root即可做到root用戶ftp登陸。
具體方法如下:
1)用root登陸
2)vi /etc/vsftpd/user_list,注釋root:
# vsftpd userlist
# If userlist_deny=NO, only allow users in this file
# If userlist_deny=YES (default), never allow users in this file, and
# do not even prompt for a password.
# Note that the default vsftpd pam config also checks /etc/vsftpd/ftpusers
# for users that are denied.
#root
bin
daemon
adm
lp
sync
shutdown
halt
news
uucp
operator
games
nobody
3)vi /etc/vsftpd/ftpusers,注釋root:
# Users that are not allowed to login via ftp
#root
bin
daemon
adm
lp
sync
shutdown
halt
news
uucp
operator
games
nobody
- 8. 【設置提示符】
Bash下具體設置方法如下:
1)用戶登陸
2)vi .profile或者vi .bashrc
3)添加如下語句(該設置的效果是“[用戶名@主機名:路徑名]#”):
export PS1="[\u@\h:\w]# "
(注意,如果對所有用戶設定,以上語句追加到/etc/profile。)
4)重新登陸,登陸顯示為:
[chyy@localhost:~/Documents/ftp資料]#
順便提一下,在CSH或TCSH下,應該修改.cshrc或.tcshrc文件,修改語句是:
set prompt="[`whoami`@`hostname`:`pwd`]# "
- 9. 【設置默認語言】
設置方法如下:
1)用root用戶登陸
2)vi /etc/sysconfig/i18n
該文件內容是:
LANG="zh_CN.UTF-8"
SYSFONT="latarcyrheb-sun16"
SUPPORTED="zh_CN.UTF-8:zh_CN:zh"
3)修改為:
LANG="en_US.UTF-8"
SUPPORTED="en_US.UTF-8:en_US:en"
SYSFONT="latarcyrheb-sun16"
- 10. 【設置默認啟動系統】
設置方法如下:
1)用root用戶登陸
2)cp /boot/grub/menu.lst /boot/grub/menu.lst.bak
3)vi /boot/grub/menu.lst
4)從0開始數title,那個title下的操作系統是默認,就將default設置為該title對應的序數
示例,以下內容中,如果default為0,代表默認從Fedora啟動;為1,代表從Windows啟動:
#boot=/dev/hda
default=0
timeout=5
splashimage=(hd0,6)/boot/grub/splash.xpm.gz
hiddenmenu
title Fedora Core (2.6.18-1.2798.fc6xen)
root (hd0,6)
kernel /boot/xen.gz-2.6.18-1.2798.fc6
module /boot/vmlinuz-2.6.18-1.2798.fc6xen ro root=LABEL=/1 rhgb quiet
module /boot/initrd-2.6.18-1.2798.fc6xen.img
title Dos
rootnoverify (hd0,0)
chainloader +1
- 11. 【設置Telnet下的Vim顏色】
設置方法如下:
1)用戶登陸
2)cp /usr/share/vim/vim70/vimrc_example.vim .vimrc
3)vi .vimrc,添加如下藍色語句(最好手動敲入,^[的輸入方式是Ctrl-v然后輸入Esc)
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif
" added by chyy
if !has("gui_running")
syntax on
set t_Co=8
set t_Sf=^[[3%p1%dm
set t_Sb=^[[4%p1%dm
colorscheme desert
endif
4)在SecureCRT的模擬終端類型選擇ANSI,並鈎上ANSI Color
5)如果需要更換顏色設置,更改colorscheme一句即可,例如:
colorscheme default
小竅門:如果不清楚有哪些顏色選項的話,可以用vi打開一個.c文件,鍵入”: colorscheme“,鍵入空格,然后敲TAB按鈕,vi會自動切換各種顏色選項的名稱。
6)注意,某些vimrc_example.vim文件中有個bug:
" In an xterm the mouse should work quite well, thus enable it.
set mouse=a
在非xterm環境(如Telnet)下,該句會導致vi無法正常運行,建議修改如下:
" In an xterm the mouse should work quite well, thus enable it.
if has("gui_running")
set mouse=a
endif
- 12. 【啟動samba服務】
設置方法如下:
1)啟動smb服務
service smb start
2)開啟suseLinux權限
setsebool -P samba_enable_home_dirs on
注意:如果想開機自動啟動smb服務,將上述兩句命令加入/etc/rc.d/rc.local即可。
二、 Linux常用系統命令
- 1. 【crontab定時任務設置】
Crontab文件放在/etc/下,其內容一般是:
[root@localhost:/etc]# cat crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
格式說明如下:
第一道第五個字段的整數取值范圍及意義是:
0~59 表示分
1~23 表示小時
1~31 表示日
1~12 表示月份
0~6 表示星期(其中0表示星期日)
- 2. 【shutdown關機】
用man查詢命令:
[root@localhost:/etc]# man shutdown
SHUTDOWN(8) Linux System Administrator鈥檚 Manual SHUTDOWN(8)
NAME
shutdown - bring the system down
SYNOPSIS
/sbin/shutdown [-t sec] [-arkhncfFHP] time [warning-message]
DESCRIPTION
shutdown brings the system down in a secure way. All logged-in users are notified that the system is going down, and login(1) is blocked. It is possible to shut the system down immediately or after a specified delay. All processes are first notified that the system is going down by the signal SIGTERM. This gives programs like vi(1) the time to save the file being edited, mail and news pro-cessing programs a chance to exit cleanly, etc. shutdown does its job by signalling the init pro- cess, asking it to change the runlevel. Runlevel 0 is used to halt the system, runlevel 6 is used to reboot the system, and runlevel 1 is used to put to system into a state where administrative tasks can be performed; this is the default if neither the -h or -r flag is given to shutdown. To see which actions are taken on halt or reboot see the appropriate entries for these runlevels in the file /etc/inittab.
OPTIONS
-a Use /etc/shutdown.allow.
-t sec Tell init(8) to wait sec seconds between sending processes the warning and the kill signal, before changing to another runlevel.
-k Don鈥檛 really shutdown; only send the warning messages to everybody.
-r Reboot after shutdown.
-h Halt or poweroff after shutdown.
-H Halt action is to halt or drop into boot monitor on systems that support it.
-P Halt action is to turn off the power.
-n [DEPRECATED] Don鈥檛 call init(8) to do the shutdown but do it ourself. The use of this option is discouraged, and its results are not always what you鈥檇 expect.
-f Skip fsck on reboot.
-F Force fsck on reboot.
-c Cancel an already running shutdown. With this option it is of course not possible to give the time argument, but you can enter a explanatory message on the command line that will be sent to all users.
time When to shutdown.
warning-message
Message to send to all users.
The time argument can have different formats. First, it can be an absolute time in the format hh:mm, in which hh is the hour (1 or 2 digits) and mm is the minute of the hour (in two digits). Second, it can be in the format +m, in which m is the number of minutes to wait. The word now is an alias for +0.
命令示例:
shutdown -h now 立即關機
shutdown -h 50 50分鍾后關機
shutdown –t 54000 15小時后自動關機
- 3. 【rpm軟件安裝卸載工具】
1) 查詢rpm軟件包:
rpm -qa | grep xxx
2) 安裝rpm軟件包:
rpm -ivh xxx.rpm
3) 卸載rpm軟件包:
rpm -e xxx
4) 修復rpm庫(執行以前先備份/var/lib/rpm目錄):
rpm --rebuilddb
- 4. 【mount掛載磁盤】
1)掛載u盤:
mount -t vfat /dev/sda1 /mnt/u
2)掛載Windows磁盤:
mount -t vfat /dev/hda1 /mnt/c -o iocharset=cp936, codepage=936
3)掛載iso系統:
mount /mnt/e/linux/fc6.iso /root/iso/ -o loop
4)掛載光盤:
mount /dev/cdrom -t iso9660 /media/cdrom
4)掛載遠程Windows共享目錄:
mount -t cifs -o username=administrator,password=123456 192.168.1.20:Download /mnt/share
其中administrator和123456分別是用戶名和密碼,192.168.1.20是Win IP,Download是共享目錄,/mnt/share是掛載目錄(必須首先創建好)
- 5. 【date查詢和設置系統時間】
用man查詢命令:
NAME
date - print or set the system date and time
SYNOPSIS
date [OPTION]... [+FORMAT]
date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
DESCRIPTION
Display the current time in the given FORMAT, or set the system date.
-d, --date=STRING
display time described by STRING, not 鈥榥ow鈥?
-f, --file=DATEFILE
like --date once for each line of DATEFILE
-s, --set=STRING
set time described by STRING
-u, --utc, --universal
print or set Coordinated Universal Time
示例一,查詢系統時間:
[chenyaya:~]# date
Mon Feb 1 11:52:33 CST 2010
示例二,設置系統時間:
[chenyaya:~]# date -s 12:31:00
Mon Feb 1 12:31:00 CST 2010
示例二,設置系統時間:
[chenyaya:~]# date -u 0201123110
Mon Feb 1 12:31:00 UTC 2010
[chenyaya:~]# date
Mon Feb 1 20:31:00 CST 2010
- 6. 【groupadd增加用戶組】
語法結構是:
groupadd [-g gid] group
說明:
g 制定組的ID號
gid 組的ID號(不能與現有的組ID號重復)
group 組名
示例:
#groupadd –g 100 sun
- 7. 【netstat查詢網絡端口】
語法結構是:
[root@localhost ~]# netstat --help
usage: netstat [-veenNcCF] [<Af>] -r netstat {-V|--version|-h|--help}
netstat [-vnNcaeol] [<Socket> ...]
netstat { [-veenNac] -I[<Iface>] | [-veenNac] -i | [-cnNe] -M | -s } [delay]
-r, --route display routing table
-I, --interfaces=<Iface> display interface table for <Iface>
-i, --interfaces display interface table
-g, --groups display multicast group memberships
-s, --statistics display networking statistics (like SNMP)
-M, --masquerade display masqueraded connections
-v, --verbose be verbose
-n, --numeric don't resolve names
--numeric-hosts don't resolve host names
--numeric-ports don't resolve port names
--numeric-users don't resolve user names
-N, --symbolic resolve hardware names
-e, --extend display other/more information
-p, --programs display PID/Program name for sockets
-c, --continuous continuous listing
-l, --listening display listening server sockets
-a, --all, --listening display all sockets (default: connected)
-o, --timers display timers
-F, --fib display Forwarding Information Base (default)
-C, --cache display routing cache instead of FIB
-T, --notrim stop trimming long addresses
-Z, --context display SELinux security context for sockets
<Iface>: Name of interface to monitor/list.
<Socket>={-t|--tcp} {-u|--udp} {-S|--sctp} {-w|--raw} {-x|--unix} --ax25 --ipx --netrom
<AF>=Use '-A <af>' or '--<af>'; default: inet
List of possible address families (which support routing):
inet (DARPA Internet) inet6 (IPv6) ax25 (AMPR AX.25)
netrom (AMPR NET/ROM) ipx (Novell IPX) ddp (Appletalk DDP)
x25 (CCITT X.25)
示例:查詢所有端口和相應的程序,不解析主機名
[root@localhost ~]# netstat -anp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 822/rpcbind
tcp 0 0 0.0.0.0:56912 0.0.0.0:* LISTEN 835/rpc.statd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1405/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 902/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1230/sendmail: acce
tcp 0 0 192.168.10.147:22 192.168.10.230:40729 ESTABLISHED 1531/0
tcp 0 0 :::111 :::* LISTEN 822/rpcbind
……
Active UNIX domain sockets (servers and established)
Proto RefCnt Flags Type State I-Node PID/Program name Path
unix 2 [ ACC ] STREAM LISTENING 9214 891/avahi-daemon: r /var/run/avahi-daemon/socket
unix 2 [ ACC ] STREAM LISTENING 9263 902/cupsd /var/run/cups/cups.sock
……
- 8. 【BASH提示符設置】
\a ASCII 響鈴字符(也可以鍵入 \007)
\d "Wed Sep 06" 格式的日期
\e ASCII 轉義字符(也可以鍵入 \033)
\h 主機名的第一部分(如 "mybox")
\H 主機的全稱(如 "mybox.mydomain.com")
\j 在此 shell 中通過按 ^Z 掛起的進程數
\l 此 shell 的終端設備名(如 "ttyp4")
\n 換行符
\r 回車符
\s shell 的名稱(如 "bash")
\t 24 小時制時間(如 "23:01:01")
\T 12 小時制時間(如 "11:01:01")
\@ 帶有 am/pm 的 12 小時制時間
\u 用戶名
\v bash 的版本(如 2.04)
\V Bash 版本(包括補丁級別) ?/td>
\w 當前工作目錄(如 "/home/drobbins")
\W 當前工作目錄的“基名 (basename)”(如 "drobbins")
\! 當前命令在歷史緩沖區中的位置
\# 命令編號(只要您鍵入內容,它就會在每次提示時累加)
\$ 如果您不是超級用戶 (root),則插入一個 "$";如果您是超級用戶,則顯示一個 "#"
\xxx 插入一個用三位數 xxx(用零代替未使用的數字,如 "\007")表示的 ASCII 字符
\\ 反斜杠
\[ 這個序列應該出現在不移動光標的字符序列(如顏色轉義序列)之前。它使 bash 能夠正確計算自動換行。
\] 這個序列應該出現在非打印字符序列之后。
- 9. 【常用壓縮格式的壓縮與解壓方法】
.tar
解包: tar xvf FileName.tar
打包:tar cvf FileName.tar DirName
(注:tar是打包,不是壓縮!)
---------------------------------------------
.gz
解壓1:gunzip FileName.gz
解壓2:gzip -d FileName.gz
壓縮:gzip FileName
.tar.gz
解壓:tar zxvf FileName.tar.gz
壓縮:tar zcvf FileName.tar.gz DirName
---------------------------------------------
.bz2
解壓1:bzip2 -d FileName.bz2
解壓2:bunzip2 FileName.bz2
壓縮: bzip2 -z FileName
.tar.bz2
解壓:tar jxvf FileName.tar.bz2
壓縮:tar jcvf FileName.tar.bz2 DirName
---------------------------------------------
.bz
解壓1:bzip2 -d FileName.bz
解壓2:bunzip2 FileName.bz
壓縮:未知
.tar.bz
解壓:tar jxvf FileName.tar.bz
壓縮:未知
---------------------------------------------
.Z
解壓:uncompress FileName.Z
壓縮:compress FileName
.tar.Z
解壓:tar Zxvf FileName.tar.Z
壓縮:tar Zcvf FileName.tar.Z DirName
---------------------------------------------
.tgz
解壓:tar zxvf FileName.tgz
壓縮:未知
.tar.tgz
解壓:tar zxvf FileName.tar.tgz
壓縮:tar zcvf FileName.tar.tgz FileName
---------------------------------------------
.zip
解壓:unzip FileName.zip
壓縮:zip FileName.zip DirName
---------------------------------------------
.rar
解壓:rar a FileName.rar
壓縮:r ar e FileName.rar
三、 SHELL常用命令
- 1. 【find文件查找】
用man查詢命令:
NAME
find - search for files in a directory hierarchy
SYNOPSIS
find [-H] [-L] [-P] [path...] [expression]
OPTIONS
-iname pattern
Like -name, but the match is case insensitive. For example, the patterns ‘fo*’ and ‘F??’ match the file names ‘Foo’, ‘FOO’, ‘foo’, ‘fOo’, etc. In these patterns, unlike file name expansion by the shell, an initial ‘.’ can be matched by ‘*’. That is, find -name *bar will match the file ‘.foobar’. Please note that you should quote patterns as a matter of course, otherwise the shell will expand any wildcard characters in them.
-type c
File is of type c:
b block (buffered) special
c character (unbuffered) special
d directory
p named pipe (FIFO)
f regular file
l symbolic link; this is never true if the -L option or the -follow option is in effect, unless the symbolic link is broken. If you want to search for symbolic links when –L is in effect, use -xtype.
s socket
D door (Solaris)
-print True; print the full file name on the standard output, followed by a newline. If you are piping the output of find into another program and there is the faintest possibility that the files which you are searching for might contain a newline, then you should seriously consider using the ‘-print0’ option instead of ’-print’. See the UNUSUAL FILENAMES section for information about how unusual characters in filenames are handled.
示例一,查找文件:
[chyy@localhost:~/isos/generic0429]# find . -name gateway
./system/gateway
示例二,查找非目錄的文件:
[chyy@localhost:~/isos/generic0429]# find . ! -type d -name ‘*’
- 2. 【file文件類型查詢】
用man查詢命令:
NAME
file - determine file type
SYNOPSIS
file [ -bchikLnNprsvz ] [ -f namefile ] [ -F separator ] [ -m magicfiles ] file ...
file -C [ -m magicfile ]
OPTIONS
-f, --files-from namefile
Read the names of the files to be examined from namefile (one per line) before the argument list. Either namefile or at least one filename argument must be present; to test the standard input, use ‘’-‘’ as a filename argument.
示例一,查詢文件類型:
[chyy@localhost:~/isos/generic0429/system]# file gateway
gateway: ASCII English text
示例二,查詢文件類型:
[chyy@localhost:~/isos/generic0429]# file build.sh
build.sh: Bourne shell script text executable
- 3. 【cut裁減文件內容】
用man查詢命令:
NAME
cut - remove sections from each line of files
SYNOPSIS
cut [OPTION]... [FILE]...
DESCRIPTION
-d, --delimiter=DELIM
use DELIM instead of TAB for field delimiter
-f, --fields=LIST
select only these fields; also print any line that contains no delimiter character, unless the -s option is specified
示例,分解並輸出各選項:
DEVICES="ttyS0,c,4,64 console,c,4,64 null,c,1,3 mtd,b,31,0"
for dev in $DEVICES; do
name=`echo $dev |cut -d"," -f1`
type=`echo $dev |cut -d"," -f2 `
major=`echo $dev |cut -d"," -f3 `
minor=`echo $dev |cut -d"," -f4 `
mknod -m666 $RAMFSDIR/dev/$name $type $major $minor
done
- 4. 【select打印用戶選擇界面】
BASH 中提供了一個小的語句格式,可以讓程序快速的設計出一個字符界面的用戶交互選擇的菜單,該功能就是由 select 語句來實現的,select 語句的語法為:
select var in [list]
do
statments use $var
done
上面的語法結構在執行后,BASH 會將 [list] 中的所有項加上數字列在屏幕上等待用戶選擇,在用戶作出選擇后,變量 $var 中就包含了那個被選中的字符串,然后就可以對該變量進行需要的操作了。
示例:
#!/bin/bash
OPTIONS="Hello Quit"
select opt in $OPTIONS; do
if [ "$opt" = "Quit" ]; then
echo done
exit
elif [ "$opt" = "Hello" ]; then
echo Hello World
else
clear
echo bad option
fi
done
exit 0
- 5. 【sed 模式匹配過濾】
用man查詢命令:
NAME
sed - stream editor for filtering and transforming text
SYNOPSIS
sed [OPTION]... {script-only-if-no-other-script} [input-file]...
DESCRIPTION
Sed is a stream editor. A stream editor is used to perform basic text transformations on an input stream (a file or input from a pipeline). While in some ways similar to an editor which permits scripted edits (such as ed), sed works by making only one pass over the input(s), and is consequently more efficient. But it is sed’s ability to filter text in a pipeline which particularly distin-guishes it from other types of editors.
-n, --quiet, --silent
suppress automatic printing of pattern space
-e script, --expression=script
add the script to the commands to be executed
-f script-file, --file=script-file
add the contents of script-file to the commands to be executed
-l N, --line-length=N
specify the desired line-wrap length for the ‘l’ command
COMMAND SYNOPSIS
This is just a brief synopsis of sed commands to serve as a reminder to those who already know sed; other documentation (such as the texinfo document) must be consulted for fuller descriptions.
= Print the current line number.
d Delete pattern space. Start next cycle.
p Print the current pattern space.
s/regexp/replacement/
Attempt to match regexp against the pattern space. If successful, replace that portion matched with replacement. The replacement may contain the special character & to refer to that portion of the pattern space which matched, and the special escapes \1 through \9 to refer to the corresponding matching sub-expressions in the regexp.
Addresses
Sed commands can be given with no addresses, in which case the command will be executed for all input lines; with one address, in which case the command will only be executed for input lines which match that address; or with two addresses, in which case the command will be executed for all input lines which match the inclusive range of lines starting from the first address and continuing to the second address. Three things to note about address ranges: the syntax is addr1,addr2 (i.e., the addresses are separated by a comma); the line which addr1 matched will always be accepted, even if addr2 selects an earlier line; and if addr2 is a regexp, it will not be tested against the line that addr1 matched.
After the address (or address-range), and before the command, a ! may be inserted, which specifies that the command shall only be executed if the address (or address-range) does not match.
The following address types are supported:
number Match only the specified line number.
/regexp/
Match lines matching the regular expression regexp.
addr1,+N
Will match addr1 and the N lines following addr1.
示例,
打印comp.flist中的某一段內容,從“bridge-utils”開始,到空行結束:
[chyy@localhost:~/GEPON/Src/ADK/make]# sed -n /^bridge-utils/,/^$/p comp.flist
bridge-utils:
usr/lib/libbridge.a
usr/share/man/man8/brctl.8
usr/sbin/brctl
usr/include/libbridge.h
[chyy@localhost:~/GEPON/Src/ADK/make]#
打印comp.flist中的第5行到7行:
[chyy@localhost:~/GEPON/Src/ADK/make]# sed -n 5,10p comp.flist
etc/ath/apcfg
etc/ath/apdown
etc/ath/apup
- 6. 【grep 模式匹配查詢】
用man查詢命令:
NAME
grep, egrep, fgrep - print lines matching a pattern
SYNOPSIS
grep [options] PATTERN [FILE...]
grep [options] [-e PATTERN | -f FILE] [FILE...]
DESCRIPTION
Grep searches the named input FILEs (or standard input if no files are named, or the file name - is given) for lines containing a match to the given PATTERN. By default, grep prints the matching lines.
In addition, two variant programs egrep and fgrep are available. Egrep is the same as grep -E. Fgrep is the same as grep -F.
OPTIONS
-H, --with-filename
Print the filename for each match.
-h, --no-filename
Suppress the prefixing of filenames on output when multiple files are searched.
-I Process a binary file as if it did not contain matching data; this is equivalent to the --binary-files=without-match option.
-i, --ignore-case
Ignore case distinctions in both the PATTERN and the input files.
-n, --line-number
Prefix each line of output with the line number within its input file.
-R, -r, --recursive
Read all files under each directory, recursively; this is equivalent to the -d recurse option.
-v, --invert-match
Invert the sense of matching, to select non-matching lines.
-w, --word-regexp
Select only those lines containing matches that form whole words. The test is that the matching substring must either be at the beginning of the line, or preceded by a non-word constituent character. Similarly, it must be either at the end of the line or followed by a non-word constituent character. Word-constituent characters are letters, digits, and the underscore.
示例
查詢包含‘packages’的Makefile文件,並打印出文件名和行號:
[chyy@localhost:~/GEPON/Src/ADK]# grep -nwH packages Makefile
Makefile:51: make -C packages
Makefile:54: make -C packages clean
查詢某個目錄下所有文件,包括子目錄,匹配整個單詞,並且不查找二進制文件,打印出行號:
[chyy@localhost:~/gv8/target]# grep -RwnI sm *
查詢文件comp.flist中“bridge-utils”起始的一段內容,並刪除“bridge-utils”:
[chyy@localhost:~/GEPON/Src/ADK/make]# sed -n /^bridge-utils/,/^$/p comp.flist | grep -v bridge-utils
usr/lib/libbridge.a
usr/share/man/man8/brctl.8
usr/sbin/brctl
usr/include/libbridge.h
[chyy@localhost:~/GEPON/Src/ADK/make]#
- 7. 【du獲取文件大小】
用man查詢命令:
NAME
du - estimate file space usage
SYNOPSIS
du [OPTION]... [FILE]...
du [OPTION]... --files0-from=F
DESCRIPTION
Summarize disk usage of each FILE, recursively for directories.
Mandatory arguments to long options are mandatory for short options too.
-a, --all
write counts for all files, not just directories
-h, --human-readable
print sizes in human readable format (e.g., 1K 234M 2G)
-s, --summarize
display only a total for each argument
示例,查詢某個目錄下各個目錄大小:
[chyy@localhost:~/cyytest]# du -sh *
24K countCache
84K createCode
40K dat
1.1M elf
4.3M html
- 8. 【ls列舉目錄內容】
用man查詢命令:
NAME
ls - list directory contents
SYNOPSIS
ls [OPTION]... [FILE]...
DESCRIPTION
List information about the FILEs (the current directory by default). Sort entries alphabetically if
none of -cftuvSUX nor --sort.
Mandatory arguments to long options are mandatory for short options too.
-a, --all
do not ignore entries starting with .
--color[=WHEN]
control whether color is used to distinguish file types. WHEN may be ‘never’, ‘always’, or ‘auto’
-R, --recursive
list subdirectories recursively
-x list entries by lines instead of by columns
-1 list one file per line
By default, color is not used to distinguish types of files. That is equivalent to using --color=none. Using the --color option without the optional WHEN argument is equivalent to using --color=always. With --color=auto, color codes are output only if standard output is connected to a terminal (tty). The environment variable LS_COLORS can influence the colors, and can be set easily by the dircolors command.
示例,列舉目錄下的文件結構:
[chyy@localhost:~/isos/work_isos/source/quantum/boards]# ls -Rx
.:
default
./default:
bs_default.c quantum quantum_boards_default.module
./default/quantum:
bs
./default/quantum/bs:
bs_board.h
- 9. 【tree列舉樹形目錄結構】
用man查詢命令:
NAME
tree - list contents of directories in a tree-like format.
SYNOPSIS
tree [-adfgilnopqrstuxACDFNS] [-L level [-R]] [-H baseHREF] [-T title] [-o filename] [--nolinks] [-P pattern] [-I pattern] [--inodes] [--device] [--noreport] [--dirsfirst] [--version] [--help] [directory ...]
OPTIONS
Tree understands the following command line switches:
-d List directories only.
-f Prints the full path prefix for each file.
-s Print the size of each file along with the name.
-D Print the date of the last modification time for the file listed.
-C Turn colorization on always, using built-in color defaults if the LS_COLORS environment variable is not set. Useful to colorize output to a pipe.
-A Turn on ANSI line graphics hack when printing the indentation lines.
-L level Max display depth of the directory tree.
-R Recursively cross down the tree each level directories (see -L option), and at each of them execute tree again adding ‘00Tree.html’ as a new option.
-T title Sets the title and H1 header string in HTML output mode.
-o filename Send output to filename.
FILES
/etc/DIR_COLORS System color database.
~/.dircolors Users color database.
ENVIRONMENT
LS_COLORS Color information created by dircolors
TREE_CHARSET Character set for tree to use in HTML mode.
LC_CTYPE Locale for filename output.
示例,用樹形顯示目錄結構:
[chyy@localhost:~/isos/work_isos/source/quantum/boards]# tree
.
`-- default
|-- bs_default.c
|-- quantum
| `-- bs
| `-- bs_board.h
`-- quantum_boards_default.module
3 directories, 3 files
- 10. 【df獲取系統空間使用情況】
用man查詢命令:
NAME
df - report file system disk space usage
SYNOPSIS
df [OPTION]... [FILE]...
OPTIONS
Show information about the file system on which each FILE resides, or all file systems by default.
Mandatory arguments to long options are mandatory for short options too.
-a, --all
include dummy file systems
-k like --block-size=1K
示例,整個各個磁盤剩余空間:
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/hda7 27769928 21137868 5198664 81% /
tmpfs 257616 0 257616 0% /dev/shm
df: `/root/iso/fc6': Permission denied
(/root/iso/fc6是由root建立的虛擬光盤系統,因為權限不夠,所以該系統空間不顯示。)
- 11. 【free查看系統內存】
用free查詢命令:
NAME
free - Display amount of free and used memory in the system
SYNOPSIS
free [-b | -k | -m] [-o] [-s delay ] [-t] [-V]
OPTIONS
The -b switch displays the amount of memory in bytes; the -k switch (set by default) displays it in kilobytes; the -m switch displays it in megabytes.
示例,系統剩余內存:
[chyy@localhost:~]# free -k
total used free shared buffers cached
Mem: 515232 489492 25740 0 263696 147236
-/+ buffers/cache: 78560 436672
Swap: 642560 0 642560
- 12. 【top查看進程內存】
用top查詢命令:
NAME
top - display Linux tasks
SYNOPSIS
top -hv | -bcHisS -d delay -n iterations -p pid [, pid ...]
示例:
[chyy@localhost:~]# top
top - 17:36:10 up 19 min, 3 users, load average: 1.74, 1.77, 1.19
Tasks: 90 total, 5 running, 85 sleeping, 0 stopped, 0 zombie
Cpu(s): 75.3%us, 23.0%sy, 0.0%ni, 0.0%id, 1.7%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 515232k total, 461436k used, 53796k free, 224048k buffers
Swap: 642560k total, 4k used, 642556k free, 153920k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
26208 ff 22 0 5440 1940 516 R 4.3 0.4 0:00.13 cpp0
26209 ff 21 0 7804 3904 1708 R 2.0 0.8 0:00.06 cc1plus
26096 chyy 15 0 2164 1004 796 R 0.3 0.2 0:00.02 top
1 root 15 0 2032 644 548 S 0.0 0.1 0:00.70 init
2 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
……
- 13. 【ps查看進程】
用ps查詢命令:
NAME
ps - report a snapshot of the current processes.
SYNOPSIS
ps [options]
EXAMPLES
To see every process on the system using standard syntax:
ps -e
ps -ef
ps -eF
ps -ely
To see every process on the system using BSD syntax:
ps ax
ps axu
To print a process tree:
ps -ejH
ps axjf
To get info about threads:
ps -eLf
ps axms
To get security info:
ps -eo euser,ruser,suser,fuser,f,comm,label
ps axZ
ps -eM
To see every process running as root (real & effective ID) in user format:
ps -U root -u root u
To see every process with a user-defined format:
ps -eo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm
ps axo stat,euid,ruid,tty,tpgid,sess,pgrp,ppid,pid,pcpu,comm
ps -eopid,tt,user,fname,tmout,f,wchan
Print only the process IDs of syslogd:
ps -C syslogd -o pid=
Print only the name of PID 42:
ps -p 42 -o comm=
SIMPLE PROCESS SELECTION
-e Select all processes. Identical to -A.
OUTPUT FORMAT CONTROL
-f does full-format listing. This option can be combined with many other UNIX-style options to add additional columns. It also causes the command arguments to be printed. When used with -L, the NLWP (number of threads) and LWP (thread ID) columns will be added. See the c option, the format keyword args, and the format keyword comm.
-o format user-defined format.
format is a single argument in the form of a blank-separated or comma-separated list, which offers a way to specify individual output columns. The recognized keywords are described in the STANDARD FORMAT SPECIFIERS section below. Headers may be renamed (ps -o pid,ruser=RealUser -o comm=Command) as desired. If all column headers are empty (ps -o pid= -o comm=) then the header line will not be output. Column width will increase as needed for wide headers; this may be used to widen up columns such as WCHAN (ps -o pid,wchan=WIDE-WCHAN-COLUMN -o comm). Explicit width control (ps opid,wchan:42,cmd) is offered too. The behavior of ps -o pid=X,comm=Y varies with personality; output may be one column named "X,comm=Y" or two columns named "X" and "Y". Use multiple -o options when in doubt. Use the PS_FORMAT environment variable to specify a default as desired; DefSysV and DefBSD are macros that may be used to choose the default UNIX or BSD columns.
OUTPUT MODIFIERS
O order Sorting order. (overloaded)
The BSD O option can act like -O (user-defined output format with some common fields predefined) or can be used to specify sort order. Heuristics are used to determine the behavior of this option. To ensure that the desired behavior is obtained (sorting or formatting), specify the option in some other way (e.g. with -O or --sort). For sorting, obsolete BSD O option syntax is O[+|-]k1[,[+|-]k2[,...]]. It orders the processes listing according to the multilevel sort specified by the sequence of one-letter short keys k1, k2, ... described in the OBSOLETE SORT KEYS section below. The "+" is currently optional, merely re-iterating the default direction on a key, but may help to distinguish an O sort from an O format. The "-" reverses direction only on the key it precedes.
--sort spec specify sorting order. Sorting syntax is [+|-]key[,[+|-]key[,...]] Choose a multi-letter key from the STANDARD FORMAT SPECIFIERS section. The "+" is optional since default direction is increasing numerical or lexicographic order. Identical to k. For example: ps jax --sort=uid,-ppid,+pid
OBSOLETE SORT KEYS
These keys are used by the BSD O option (when it is used for sorting). The GNU --sort option doesn’t use these keys, but the specifiers described below in the STANDARD FORMAT SPECIFIERS section. Note that the values used in sorting are the internal values ps uses and not the "cooked" values used in some of the output format fields (e.g. sorting on tty will sort into device number, not according to the terminal name displayed). Pipe ps output into the sort(1) command if you want to sort the cooked values.
KEY LONG DESCRIPTION
c cmd simple name of executable
C pcpu cpu utilization
o session session ID
p pid process ID
P ppid parent process ID
s size memory size in kilobytes
t tty the device number of the controlling tty
T start_time time process was started
U uid user ID number
u user user name
……
STANDARD FORMAT SPECIFIERS
Here are the different keywords that may be used to control the output format (e.g. with option -o) or to
sort the selected processes with the GNU-style --sort option.
For example: ps -eo pid,user,args --sort user
This version of ps tries to recognize most of the keywords used in other implementations of ps.
The following user-defined format specifiers may contain spaces: args, cmd, comm, command, fname, ucmd, ucomm, lstart, bsdstart, start.
Some keywords may not be available for sorting.
CODE HEADER DESCRIPTION
%cpu %CPU cpu utilization of the process in "##.#" format. Currently, it is the CPU time used divided by the time the process has been running (cputime/realtime ratio), expressed as a percentage. It will not add up to 100% unless you are lucky. (alias pcpu).
%mem %MEM ratio of the process鈥檚 resident set size to the physical memory on the machine, expressed as a percentage. (alias pmem).
args COMMAND command with all its arguments as a string. Modifications to the arguments may be shown. The output in this column may contain spaces. A process marked <defunct> is partly dead, waiting to be fully destroyed by its parent. Sometimes the process args will be unavailable; when this happens, ps will instead print the executable name in brackets. (alias cmd, command). See also the comm format keyword, the -f option, and the c option. When specified last, this column will extend to the edge of the display. If ps can not determine display width, as when output is redirected (piped) into a file or another command, the output width is undefined. (it may be 80, unlimited, determined by the TERM variable, and so on) The COLUMNS environment variable or --cols option may be used to exactly determine the width in this case. The w or -w option may be also be used to adjust width.
cmd CMD see args. (alias args, command).
示例:
1) 查詢所有進程,輸出PID、用戶名、命令和CPU利用率,並按照cpu利用率排序
[chyy@localhost:~]# ps -eo pid,user,%cpu,args --sort %cpu
PID USER %CPU COMMAND
2 root 0.0 [migration/0]
3 root 0.0 [ksoftirqd/0]
4 root 0.0 [watchdog/0]
5 root 0.0 [events/0]
6 root 0.0 [khelper]
7 root 0.0 [kthread]
10 root 0.0 [kblockd/0]
……
2185 68 0.0 hald
26293 root 0.0 make -C router install
26920 root 93.3 /home/chyy/EPON/work/ToolChain/arm-uclibc-3.4.6/bin/../libexec/gcc/arm-linux-uclibc/3.4.6/cc1 -quiet
2) 查詢所有進程,輸出所有,並按照cpu利用率排序
[chyy@localhost:~]# ps -ef O+C
UID PID PPID C STIME TTY STAT TIME CMD
root 2 1 0 09:35 ? S 0:00 [migration/0]
root 3 1 0 09:35 ? SN 0:00 [ksoftirqd/0]
……
68 2185 1 0 09:35 ? Ss 0:01 hald
root 3884 3487 0 11:27 pts/2 S+ 0:00 make -C gw_api
root 3903 3902 99 11:27 pts/2 R+ 0:00 /home/chyy/EPON/work/ToolChain/arm-uclibc-3.4.6/bin/../libexec/gcc/ar
3) 查詢所有進程,輸出所有,並按照cpu降序排序
[chyy@localhost:~]# ps -ef O-C
或者
[chyy@localhost:~]# ps -ef --sort -%cpu
UID PID PPID C STIME TTY TIME CMD
root 14895 14879 99 11:30 pts/2 00:00:04 /home/chyy/EPON/work/ToolChain/arm-uclibc-3.4.6/bin/../libexec/gcc/arm-l
68 2185 1 0 09:35 ? 00:00:01 hald
root 14050 14045 0 11:29 pts/2 00:00:00 make -C router all
……
root 14879 14877 0 11:30 pts/2 00:00:00 arm-linux-uclibc-gcc /home/chyy/EPON/work/src/router/tr069/cwmp/cwmpCPE.
chyy 14897 2825 0 11:30 pts/3 00:00:00 ps -ef --sort -%cpu
4) 查詢所有進程,輸出所有,並按照PID排序
[chyy@localhost:~]# ps -ef O+U
UID PID PPID C STIME TTY STAT TIME CMD
root 1 0 0 09:35 ? Ss 0:00 init [5]
root 2 1 0 09:35 ? S 0:00 [migration/0]
……
rpc 1825 1 0 09:35 ? Ss 0:00 portmap
gdm 2507 2463 0 09:36 ? Ss 0:00 /usr/libexec/gdmgreeter
xfs 2130 1 0 09:35 ? Ss 0:00 xfs -droppriv -daemon
……
chyy 2620 2606 0 10:10 pts/2 S 0:00 -bash
chyy 2825 2738 0 10:10 pts/3 S 0:00 -bash
chyy 25492 2825 0 11:33 pts/3 R+ 0:00 ps -ef O+U
ff 2546 2544 0 09:59 ? S 0:00 sshd: ff@pts/1
ff 2547 2546 0 09:59 pts/1 Ss+ 0:00 -bash
ff 2570 2546 0 10:00 ? Ss 0:00 /usr/libexec/openssh/sftp-server
5) 查詢所有進程,輸出所有,並按照PID升序、CPU利用率降序排序
[chyy@localhost:~]# ps -ef O+U-C
UID PID PPID C STIME TTY STAT TIME CMD
Root 3681 3655 27 11:43 pts/2 R+ 0:00 /home/chyy/EPON/work/ToolChain/arm-uclibc-3.4.6/bin/../libexec/gcc/ar
root 3655 3653 0 11:43 pts/2 S+ 0:00 arm-linux-uclibc-gcc /home/chyy/EPON/work/src/router/tr069/cwmp/cwmpC
……
root 3653 2828 0 11:43 pts/2 S+ 0:00 make -C tr069
rpc 1825 1 0 09:35 ? Ss 0:00 portmap
gdm 2507 2463 0 09:36 ? Ss 0:00 /usr/libexec/gdmgreeter
xfs 2130 1 0 09:35 ? Ss 0:00 xfs -droppriv -daemon
……
dbus 1887 1 0 09:35 ? Ss 0:00 dbus-daemon --system
chyy 2825 2738 0 10:10 pts/3 S 0:00 -bash
chyy 2620 2606 0 10:10 pts/2 S 0:00 -bash
chyy 3682 2825 0 11:43 pts/3 R+ 0:00 ps -ef O+U-C
ff 2547 2546 0 09:59 pts/1 Ss+ 0:00 -bash
ff 2570 2546 0 10:00 ? Ss 0:00 /usr/libexec/openssh/sftp-server
ff 2546 2544 0 09:59 ? S 0:00 sshd: ff@pts/1
- 14. 【dos2unix轉換文件換行符】
用dos2unix查詢命令:
NAME
dos2unix - DOS/MAC to UNIX text file format converter
SYNOPSYS
dos2unix [options] [-c convmode] [-o file ...] [-n infile outfile ...]
Options:
[-hkqV] [--help] [--keepdate] [--quiet] [--version]
OPTIONS
-k --keepdate
Keep the date stamp of output file same as input file.
-n --newfile infile outfile ...
New file mode. Convert the infile and write output to outfile. File names must be given in pairs and wildcard names should NOT be used or you WILL lost your files.
示例,轉換文件:
[chenyaya:~/FrameWork-tksdk/user/sdk/tksdk]# dos2unix -k build/mklinux.sh
dos2unix: converting file build/mklinux.sh to UNIX format ...
四、 SHELL命令靈活應用
- 1. 【拷貝目錄結構】
find SRC -type d | sed 's/SRC/mkdir -p DST/' | sh
說明:先利用find列出所有目錄,然后用sed替換為mkdir命令格式,最后用sh執行
- 2. 【查找字段並排除不需要的項】
grep –RwnI DIR PATTERN | grep –v PATTERN
說明:第一個grep負責找到包含PATTERN的內容,第二個grep刪除不需要的內容
示例:
[chenyaya:~/FrameWork/user]# grep -RwnI doswset * | grep -v .svn
eth/bcm53115/Sources/DARESWH_x_bcm_cli.c:3877:int doswset(int argc, char *cmd[])
eth/bcm53115/Sources/DARESWH_x_bcm_cli.c:3955: doswset(argc,cmd);
eth/bcm5328x/Sources/DARESWH_x_bcm_cli.c:249:int doswset(int argc, char *cmd[])
eth/bcm5328x/Sources/DARESWH_x_bcm_cli.c:328: doswset(argc,cmd);
nm_darepon.txt:1332:000548e0 T doswset
- 3. 【查找文件並刪除】
find . -name FILENAME | xargs rm -rf
說明:find找到對應文件后,用xargs作為rm的參數執行
示例:
[chenyaya:~/FrameWork/user]# find . -name .svn | xargs rm -rf
- 4. 【打包目錄並排除特定文件】
tar czvf TARGET SRC --exclude PATTERN1 --exclude PATTERN2 --exclude PATTERN3 …
說明:很多時候打包備份項目只需要里面的源文件,而中間文件如*.o等不需要打包,此時利用tar的--exclude的選項可以方便的排除掉不需要的文件。
示例:
[chenyaya:~]#tar czvf FrameWork.bak.r2637.20110629.tgz FrameWork --exclude \.svn --exclude *.o --exclude *.a --exclude *.P --exclude *.d --exclude *.ko --exclude *.so --exclude buildlog_*.txt --exclude sources --exclude Objects --exclude Libraries --exclude Binaries --exclude voip* --exclude transwitch --exclude utilities --exclude davinci --exclude docs --exclude *.doc --exclude *.tmp --exclude *.xls
五、 Windows系統常用命令
- 1. 【Word中轉換回車符】
word中有些表記不是我們常用的回車符號,而是一個向下的箭頭,這個箭頭在word中可以用“shift+Enter”鍵組合輸入。前者叫硬回車,后者叫軟回車。
軟回車的標記是“^l”,硬回車的標記是“^p”,轉換回車用“替換”功能即可。
六、 特殊說明
- 1. 【RIP使用的網絡接口結構體interface】
h/wrn/coreip/rip/interface.h/interface.h:
/*
* An ``interface'' is similar to an ifnet structure,
* except it doesn't contain q'ing info, and it also
* handles ``logical'' interfaces (remote gateways
* that we want to keep polling even if they go down).
* The list of interfaces which we maintain is used
* in supplying the gratuitous routing table updates.
*/
struct interface {
struct interface *int_next;
struct sockaddr int_addr; /* address on this host */
union {
struct sockaddr intu_broadaddr;
struct sockaddr intu_dstaddr;
} int_intu;
#define int_broadaddr int_intu.intu_broadaddr /* broadcast address */
#define int_dstaddr int_intu.intu_dstaddr /* other end of p-to-p link */
int int_metric; /* init's routing entry */
int int_flags; /* see below */
/* START INTERNET SPECIFIC */
u_long int_net; /* network # */
u_long int_netmask; /* net mask for addr */
u_long int_subnet; /* subnet # */
u_long int_subnetmask; /* subnet mask for addr */
/* END INTERNET SPECIFIC */
char *int_name; /* from kernel if structure */
u_short int_index; /* from kernel if structure */
u_short int_transitions; /* times gone up-down */
M2_RIP2_IFSTAT_ENTRY ifStat; /* MIB-II statistics. */
M2_RIP2_IFCONF_ENTRY ifConf; /* MIB-II configuration. */
FUNCPTR authHook; /* per interface authentication */
FUNCPTR leakHook; /* per interface leak hook. */
BOOL (*sendHook) (); /* per interface validation hook */
RIP_AUTH_KEY * pAuthKeys; /* list of valid authe keys */
};
重要變量說明:
1) int_flags:接口類型
具體意義參見if.h或者interface.h,前者比較全面,后者主要定義了Rip相關的定義,下面藍色部分是出現在interface.h中的定義:
#define IFF_UP 0x1 /* interface is up */
#define IFF_BROADCAST 0x2 /* broadcast address valid */
#define IFF_DEBUG 0x4 /* turn on debugging */
#define IFF_LOOPBACK 0x8 /* software loopback net */
#define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */
#define IFF_SUBNET 0x100000 /* interface on subnetted network */
#define IFF_PASSIVE 0x200000 /* can't tell if up/down */
#define IFF_INTERFACE 0x400000 /* hardware interface */
#define IFF_REMOTE 0x800000 /* interface isn't on this machine */
#define IFF_SHARED_ROUTES 0x10000000 /* shared routes may exist */
#define IFF_UP 0x1 /* interface link is up */
#define IFF_BROADCAST 0x2 /* broadcast address valid */
#define IFF_DEBUG 0x4 /* turn on debugging */
#define IFF_LOOPBACK 0x8 /* is a loopback net */
#define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */
#define IFF_SMART 0x20 /* interface manages own routes */
#define IFF_RUNNING 0x40 /* resources allocated */
#define IFF_NOARP 0x80 /* no address resolution protocol */
#define IFF_PROMISC 0x100 /* receive all packets */
#define IFF_ALLMULTI 0x200 /* receive all multicast packets */
#define IFF_OACTIVE 0x400 /* transmission in progress */
#define IFF_SIMPLEX 0x800 /* can't hear own transmissions */
#define IFF_LINK0 0x1000 /* forwarding disabled */
#define IFF_LINK1 0x2000 /* per link layer defined bit */
#define IFF_LINK2 0x4000 /* per link layer defined bit */
#define IFF_ALTPHYS IFF_LINK2 /* use alternate physical connection */
#define IFF_MULTICAST 0x8000 /* supports multicast */
#define IFF_NOTRAILERS 0x20000 /* avoid use of trailers */
#define IFF_INET_UP 0x40000 /* interface is up for ipv4 */
#define IFF_INET6_UP 0x80000 /* interface is up for ipv6 */
#define IFF_UNNUMBERED IFF_POINTOPOINT /* supports unnumbered interfaces */
#define IFF_FPV4_ENABLE 0x100000 /* supports V4 fast forwarding */
#define IFF_FPV6_ENABLE 0x200000 /* supports V6 fast forwarding */
#define IFF_PROXY_ALL 0x400000 /* enable Cisco style proxying */
#define IFF_DONT_FORWARD IFF_LINK0 /* forwarding disabled */
#define IFF_POLLING 0x10000 /* Interface is in polling mode. */
#define IFF_PPROMISC 0x800000 /* user-requested promisc mode */
一般int_flags是由多個flag組合起來的,常用的幾個int_flags的意義如下:
十進制 |
十六進制 |
意義 |
備注 |
1 |
0x1 |
IFF_UP |
|
257 |
0x101 |
IFF_PROMISC & IFF_UP |
|
294985 |
0x48049 |
IFF_INET_UP & IFF_MULTICAST & IFF_RUNNING & IFF_LOOPBACK & IFF_UP |
for lo |
393539 |
0x60143 |
IFF_INET_UP & IFF_NOTRAILERS & IFF_PROMISC & IFF_RUNNING & IFF_BROADCAST & IFF_UP |
|
426051 |
0x68043 |
IFF_INET_UP & IFF_NOTRAILERS & IFF_MULTICAST & IFF_RUNNING & IFF_BROADCAST & IFF_UP |
|
1213251 |
0x128343 |
IFF_SUBNET & IFF_NOTRAILERS & IFF_MULTICAST & IFF_ALLMULTI & IFF_PROMISC & IFF_RUNNING & IFF_BROADCAST & IFF_UP |
for wan |
1278160 |
0x1380d0 |
IFF_SUBNET & IFF_NOTRAILERS & IFF_POLLING & IFF_MULTICAST & IFF_NOARP & IFF_RUNNING & IFF_POINTOPOINT |
for ppp |
1474627 |
0x168043 |
IFF_SUBNET & IFF_INET_UP & IFF_NOTRAILERS & IFF_MULTICAST & IFF_RUNNING & IFF_BROADCAST & IFF_UP |
for lan |
|
|
|
|
- 2. 【Vx使用的網絡接口變量ifnet】
h/wrn/coreip/net/if_var.h:
struct ifnet {
void *if_softc; /* pointer to driver state */
char *if_name; /* name, e.g. ``en'' or ``lo'' */
TAILQ_ENTRY(ifnet) if_link; /* all struct ifnets are chained */
struct ifaddrhead if_addrhead; /* linked list of addresses per if */
int if_pcount; /* number of promiscuous listeners */
struct bpf_if *if_bpf; /* packet filter structure */
UINT32 ifIndex; /* external index for this if */
u_short if_index; /* internal index for this if */
short if_unit; /* sub-unit for lower level driver */
short if_timer; /* time 'til if_watchdog called */
long if_flags; /* up/down, broadcast, etc. */
int if_ipending; /* interrupts pending */
void *if_linkmib; /* link-type-specific MIB data */
size_t if_linkmiblen; /* length of above data */
struct if_data if_data;
struct ifmultihead if_multiaddrs; /* multicast addresses configured */
int if_amcount; /* number of all-multicast requests */
/* procedure handles */
int (*if_output) /* output routine (enqueue) */
(struct ifnet *, struct mbuf *, struct sockaddr *,
struct rtentry *);
void (*if_start) /* initiate output routine */
(struct ifnet *);
union {
int (*if_done) /* output complete routine */
(struct ifnet *); /* (XXX not used) */
int uif_capabilities; /* interface capabilities */
} _u1;
int (*if_ioctl) /* ioctl routine */
(struct ifnet *, u_long, caddr_t);
void (*if_watchdog) /* timer routine */
(struct ifnet *);
union {
int (*if_poll_recv) /* polled receive routine */
(struct ifnet *, int *);
int uif_capenable; /* enabled features */
} _u2;
int (*if_poll_xmit) /* polled transmit routine */
(struct ifnet *, int *);
void (*if_poll_intren) /* polled interrupt reenable routine */
(struct ifnet *);
void (*if_poll_slowinput) /* input routine for slow devices */
(struct ifnet *, struct mbuf *);
void (*if_init) /* Init routine */
(void *);
/* Clarinet - added this func pointer as it is used in the WRS code */
int (*if_resolve)(); /* arp resolve at driver level */
int (*if6_resolve)(); /* nd resolve at driver level */
int (*if_resolvemulti) /* validate/resolve multicast */
(struct ifnet *, struct sockaddr **, struct sockaddr *);
struct ifqueue if_snd; /* output queue */
struct ifqueue *if_poll_slowq; /* input queue for slow devices */
struct ifprefixhead if_prefixhead; /* list of prefixes per if */
/* Clarinet - added this cookie that holds the drv_ctrl pointer */
void * pCookie; /* data for IP over MUX attachment */
int if_adminstatus;
int admin_inet_status;
int admin_inet6_status; /* RFC 2465, admin status control for IPv6 */
uint32_t if_csum_flags_tx;
uint32_t if_csum_flags_rx;
#ifdef VIRTUAL_STACK
VSNUM vsNum;
#endif /* VIRTUAL_STACK */
#ifdef VLAN_TAG
void * pTagData; /* 802.1Q L2 VLAN tagging structure */
#endif /* VLAN_TAG */
};
其中if_flags意義和RIP類似。
具體定義在if.h中:
#define IFF_UP 0x1 /* interface link is up */
#define IFF_BROADCAST 0x2 /* broadcast address valid */
#define IFF_DEBUG 0x4 /* turn on debugging */
#define IFF_LOOPBACK 0x8 /* is a loopback net */
#define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */
#define IFF_SMART 0x20 /* interface manages own routes */
#define IFF_RUNNING 0x40 /* resources allocated */
#define IFF_NOARP 0x80 /* no address resolution protocol */
#define IFF_PROMISC 0x100 /* receive all packets */
#define IFF_ALLMULTI 0x200 /* receive all multicast packets */
#define IFF_OACTIVE 0x400 /* transmission in progress */
#define IFF_SIMPLEX 0x800 /* can't hear own transmissions */
#define IFF_LINK0 0x1000 /* forwarding disabled */
#define IFF_LINK1 0x2000 /* per link layer defined bit */
#define IFF_LINK2 0x4000 /* per link layer defined bit */
#define IFF_ALTPHYS IFF_LINK2 /* use alternate physical connection */
#define IFF_MULTICAST 0x8000 /* supports multicast */
#define IFF_NOTRAILERS 0x20000 /* avoid use of trailers */
#define IFF_INET_UP 0x40000 /* interface is up for ipv4 */
#define IFF_INET6_UP 0x80000 /* interface is up for ipv6 */
#define IFF_UNNUMBERED IFF_POINTOPOINT /* supports unnumbered interfaces */
#define IFF_FPV4_ENABLE 0x100000 /* supports V4 fast forwarding */
#define IFF_FPV6_ENABLE 0x200000 /* supports V6 fast forwarding */
#define IFF_PROXY_ALL 0x400000 /* enable Cisco style proxying */
#define IFF_DONT_FORWARD IFF_LINK0 /* forwarding disabled */
/*
* The following flag(s) ought to go in if_flags, but we cannot change
* struct ifnet because of binary compatibility, so we store them in
* if_ipending, which is not used so far.
* If possible, make sure the value is not conflicting with other
* IFF flags, so we have an easier time when we want to merge them.
*/
#define IFF_POLLING 0x10000 /* Interface is in polling mode. */
#define IFF_PPROMISC 0x800000 /* user-requested promisc mode */
- 3. 【Gcc版本查詢】
$ cc --version | head -1
cc (GCC) 3.3.4 (Debian 1:3.3.4-13)
$ ld --version | head -1
GNU ld version 2.15
- 4. 【SVN版本合並】
命令形式:
svn merge -r 1535:1561 http://172.16.16.34:8177/svn/DARE_MDU/trunk
此命令用來比較差異,並將差異加到本地源碼中(切記在本地源碼中,編譯通過后,需svn ci提交到svn服務器上)
后面的url (http://172.16.16.34:8177/svn/DARE_MDU/trunk ) 是被用來合並的的分支或主干。
svn merge使用時所在的當前路徑($PWD)應為要被合入的主干或分支的根目錄(本地路徑)
-r應該是循環的意思
1535:1561是要被合並的版本號的區間值。
若這兩個值顛倒過來寫(1561:1535),就是相反的意思了,是從本地源碼中“去掉”1535到1561之間所修改的代碼。
還有一個宏HEAD是用來表示當前最新的版本,故有下面的用法:
svn merge -r Head:1535
表示從當前源碼回撤到某個版本,即回到1535之前的那一個版本。這里后面沒有url地址,故就為當前本地源碼所對應的分支或主干地址(也就是當前分支或主干源碼回撤)。另外,-r HEAD也可不留空格,即-rHEAD.
END