LINUX常用配置及命令
一、 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
LINUX常用配置及命令的更多相关文章
- ## 本篇文章对linux常用的一些命令做一下总结,如有需要补充以及不懂得地方,请在下方留言 适合于linux初学者,以及对命令掌握不牢的用来备忘
本篇文章对linux常用的一些命令做一下总结,如有需要补充以及不懂得地方,请在下方留言 适合于linux初学者,以及对命令掌握不牢的用来备忘一,磁盘管理1.显示当前目录位置 pwd2.切换目录 cd ...
- Linux 常用的压缩命令有 gzip 和 zip
Linux 常用的压缩命令有 gzip 和 zip,两种压缩包的结尾不同:zip 压缩的后文件是 *.zip ,而 gzip 压缩后的文件 *.gz 相应的解压缩命令则是 gunzip 和 unzip ...
- linux网络配置相关命令、虚拟网络接口eth0:0
网络接口(interface)是网络硬件设备在操作系统中的表示方法,比如网卡在Linux操作系统中用ethX,是由0开始的正整数,比如eth0.eth1...... ethX.而普通猫和ADSL的接口 ...
- Java线上问题排查思路及Linux常用问题分析命令学习
前言 之前线上有过一两次OOM的问题,但是每次定位问题都有点手足无措的感觉,刚好利用星期天,以测试环境为模版来学习一下Linux常用的几个排查问题的命令. 也可以帮助自己在以后的工作中快速的排查线上问 ...
- Linux——网络配置及命令
traceroute命令(unix)/tracert命令(windows) tracert命令的格式为:tracert [-d] [-h maximum_hops] [-j host-list] [- ...
- linux常用60条命令 转
Linux必学的60个命令 Linux提供了大量的命令,利用它可以有效地完成大量的工作,如磁盘操作.文件存取.目录操作.进程管理.文件权限设定等.所以,在Linux系统上工作离不开使用系统提供的命 ...
- 入门学习Linux常用必会命令实例详解
Linux提供了大量的命令,利用它可以有效地完成大量的工作,如磁盘操作.文件存取.目录操作.进程管理.文件权限设定等.所以,在Linux系统上工作离不开使用系统提供的命令.要想真正理解Linux系统, ...
- Linux常用的基础命令总结
man 查看英文命令帮助 可以看作--help 拷贝目录的命令cp -a 包含所有 ls -a 显示所有文件包括隐藏文件 -ld ls -F 过滤目录文件(给不同类型文件结尾加上不同的符号) ...
- 网络编程学习笔记-linux常用的网络命令
网络参数设置命令 所有时刻如果你想要做好自己的网络参数设置,包括IP参数.路由参数和无线网络等,就得要了解下面这些相关的命令才行.其中Route及ip这两条命令是比较重要的.当然,比较早期的用法,我们 ...
随机推荐
- 基于linux运用python开发知识点滴
我是小白,希望我的文章能对小白们有点作用. A.Linux的开源,优势明显,如何使用,基本命令如下: 个人认为最基础的两种操作: 1.文件操作: ls 看文件夹下内容 ls -a 隐藏文件 -l非隐藏 ...
- 30道四则运算<2>单元测试
该测试未实现除法 该测试中间多了/)两个符号,而且没有等号和回车. 该测试也没有符合除法要求 该测试也没有满足除法要求 该测试满足要求. 总结:程序中涉及到有除法的输出都有问题,多次改正未果:其他条件 ...
- LinearLayout 控件
LinearLayout 控件,垂直显示各控件一行一个显示,比较好控件. 用RelativeLayout多个控件会堆在一起 <LinearLayout xmlns:android="h ...
- 【函数】oracle translate() 详解+实例
一.语法: TRANSLATE(string,from_str,to_str) 二.目的 返回将(所有出现的)from_str中的每个字符替换为to_str中的相应字符以后的string.TRAN ...
- (实用篇)php 文件夹删除,清除缓存程序
<?php header('content-type:text/html;charset=utf-8'); function delFile($fpath) { $filesize = arra ...
- Eclipse 插件安装方法和插件加载失败解决办法
一:是利用Eclipse Software Update 添加网址,让Eclipse 自动的搜索下载最新的插件. 比如安装VE这个可视化编辑UI的插件,其步骤为 Help > Software ...
- Apache搭建多个站点方法详解
www.111cn.net 编辑:Bolshevik 来源:转载 Apache的虚拟主机是一种允许在同一台机器上配置多个不同站点的web服务器环境的,就是iis一样可以创建多站点了,但是apache需 ...
- 设置drawable图片
google官方建议在textView和imageView挨着的时候,建议使用drawable来显示图片 第一个方法:setCompoundDrawablesWithIntrinsicBounds(D ...
- jQuery select操作控制方法小结
需要注意的是,这里的代码好多是针对jquery 1.32以前的版本(以后的版本已经不支持@),所以替换为空测试下即可. jQuery获取Select选择的Text和Value: 语法解释: 1. $( ...
- 科普:浅谈 Hellinger Distance
浅谈 Hellinger Distance 2016.05.24 最近在看 Hellinger Distance(海林格距离), 平时看多了欧式距离,马氏距离等等,貌似介绍这个的材料不是很多,例如:维 ...