??xml version="1.0" encoding="utf-8" standalone="yes"?>一区二区中文,日韩欧美精品在线不卡,亚洲成人精品电影在线观看http://www.aygfsteel.com/luluyanglu/category/38273.htmlzh-cnFri, 13 Mar 2009 17:02:19 GMTFri, 13 Mar 2009 17:02:19 GMT60UNIX命ohttp://www.aygfsteel.com/luluyanglu/archive/2009/03/13/259648.html大鱼大鱼Fri, 13 Mar 2009 15:10:00 GMThttp://www.aygfsteel.com/luluyanglu/archive/2009/03/13/259648.htmlhttp://www.aygfsteel.com/luluyanglu/comments/259648.htmlhttp://www.aygfsteel.com/luluyanglu/archive/2009/03/13/259648.html#Feedback0http://www.aygfsteel.com/luluyanglu/comments/commentRss/259648.htmlhttp://www.aygfsteel.com/luluyanglu/services/trackbacks/259648.htmlUNIX命o
 
 

在UNIXpȝ常用命o格式Q?
command [flags] [argument1] [argument2] ...
其中flags?开始,多个flags可用一?qv来,如ls -l -a 与ls -la相同?

Ҏ(gu)命o的不同,参数分ؓ可选的或必ȝQ所有的命o从标准输入接受输入,输出l果昄在标准输出,而错误信息则昄在标准错误输备。可使用重定向功能对
q些讑֤q行重定向??/p>

命o在正常执行结果后q回一?|如果命o出错可未完全完成Q则q回一?
非零?在shell中可用变??查看). 在shell script中可用此q回g为控刉辑
的一部分?

注:不同的UNIX版本的flags可能有所不同?

1、与用户相关的命?
1.1 login
(在LINUX Redhat下此命o功能与Solaris/BSD不同Q执行login会退出当前Q?.

login:
Password:

相关文gQ?
在下面的q些文g中设定shellq行时必要的路径,l端cd,其他变量或特D程?

$HOME/.profile (Bourne shell, sh, bash)
$HOME/.cshrc (csh, tcsh)
$HOME/.tcshrc (tcsh)
/etc/passwd文g中列出每个用Lshell
/etc/csh.cshrc
/etc/csh.login
/etc/profile (Bourne shell, bash)
/etc/login (Bourne shell, bash)

csh: /etc/csh.cshrc?HOME/.cshrc每次执行都会dQ?
?etc/csh.login?HOME/.login只有注册shell才执?
修改相应文g后?source .cshrc使能相关修改Q如果修改了path?
q需使用rehashh可执行文件hash表?

tcsh: $HOME/.tcshrc, 没有些文件读?cshrc

sh: /etc/profile?HOME/.profile注册shell
bash: /etc/profile?HOME/.bash_profile注册shelld
.bashrc交互式非注册shell才读取?

在sh/bash下手工执行相x?
. /etc/profile

相关文g执行序
sh: /etc/profile -> $HOME/.profile
csh/tcsh: /etc/csh.cshrc -> /etc/csh.login -> $HOME/.cshrc
-> $HOME/.login

变量的设|?
sh/bash: TERM=vt100; export TERM
OR: export TERM=vt100 (bash)
csh: setenv TERM vt100

常用变量:
(1)Backspace $HOME/.profile $HOME/.cshrc
stty erase ^H
(2)umask 新徏文g或目录的保护属?
(3)TERM
(4)切忌PATH中加?.

1.2. rlogin
与telnetcM,q接到远E主?

rlogin remotehost [ -l loginname ]
Or:
rsh [-l loginname] remotehost [command ]

相关文g:
q程L?/etc/hosts.equiv ?$HOME/.rhosts

相关|络配置文g:
/etc/inetd.conf文g中的rpȝ服务.Redhat下ؓshell, login, exec, 对应
的网l守护进E?daemon)为in.rshd, in.rlogind, in.rexecd.

: 从安全角度出?关闭rpd服务.

1.3. telnet
telnet remotehost [port]

相关文g:
/etc/inetd.conf文g中的telnet服务.
/etc/issue.net

TIPS: strings /usr/sbin/in.telnetd |egrep issue

1.4. passwd 更改口o

1.5 exit 退出当前shell


2. 命o或文件的查找
相关shell变量:
csh/tcsh: $path
.cshrc set path=(/usr/bin /usr/local/bin $path)
sh/bash: $PATH
.profile .bash_profile
PATH=/usr/local/bin:$PATH; export PATH

2.1 which
Syntax: which command

which为bash/tcsh内带命o
[hbwork@toshiba]$ which which
which: shell built-in command.
2.2 where(tcsh)
Syntax: where command
2.3 locate (LINUX)
Syntax: locate filename

相关命o: updatedb更改locate文g名数据库

3. 查看命o的用?
man
相关文g:
/etc/man.config

4. 理员常用命?

4.1 install
用于安装一个新的命令或daemon{? 一般情况下可以不用,但很多Y件在其安?
shell script中用install目标文件复制到相应的目录ƈ讄正确的属性等.


NAME
install - copy files and set their attributes

SYNOPSIS
install [options] [-s] [--strip] source dest
install [options] [-s] [--strip] source... directory
install [options] [-d,--directory] directory...
Options:
[-c] [-g group] [-m mode] [-o owner] [--group=group]
[--mode=mode] [--owner=owner] [--help] [--version]

4.2 shutdown
不同的unix参数不尽相同,在linux下常用如下方式关?
shutdown -h now
shutdown -r now ({同于reboot)

4.3 halt
poweroff
x,在多用户方式?Runlevel 3)不徏议?

4.4 ulimit
korn shell和bourne shell中可用此命o,在cshpd中相应的命o为limit.
用于限制每个q程可用的pȝ资源,通常分两U限?
. Hard limits pȝ所定义的资?只有root能更?
. 软限?Ҏ(gu)E所使用的限?可增加到pȝ的Hard Limit.

Flags:
-a 列出软限?
-Ha 列出Hard Limit
-c size 讄coredump size的块大小
-t size cputime
-f size file size

4.5 umask pȝ理员用于设|用户默认的umask?


5.与进E相关的命o

q程基本概念: q程与命令的执行相关,但ƈ不是一一对应; 一条命令可能对应若q?
个进E?如shell script, pipe{?.但最单的命o与umask只有一个进E?

q程分类:
.交互式进E?可以前台或后台执?前后台可切换
.批处理进E?不通过l端提交,一般将它们攑֜d队列中顺序执? 如通过
at ?crontab提交的Q?
.deamon:怸l止的进E?{待响应来自其他q程的服务请?如sendmail,
named(DNS), POP3及apache{?

q程的相兛_?
PID
Real UID
Effective UID (SUID)
Real GID
Effective GID (SGID)
Priority(Nice Number)执行的优先

5.1 ps
Process Status, 列出当前q行的进E状?Ҏ(gu)选项不同,可列出所有的或部分进E?
. 无选项时只列出从当前终端上启动的进E?SYSV)或当前用?$USER)的进E?BSD),
不同的UNIX版本之间有差? linux使用BSD版本的ps
. BSD版本ps命o使用Ҏ(gu):
ps
ps aux 列出pȝ中所有的q程的详l情?
ps aux |egrep inetd

输出信息内容:
PID
Terminal 如无相应l端则ؓ-
cpu time
UserID or Username
q程启动旉或日?
q程状?Stat: S(leep) R(unnable) D(uninterrupt sleep) Z(ombie)
W q程没有ȝ面, N: q程的nicegؓ负?

5.2 kill
kill [-signal] PID

kill -l 列出可用信号?
常用信息?
-HUP (1) 重启q程
ps ax |egrep inetd
kill -HUP pid_of_inetd
-KILL (9) 强制中止

PID取值含?
>0 指特定进E?实际q程)
=0 同组用户的所有process(PGID)
=-1 Effective UID = 执行命o用户之uid
<0 && !=1 取绝对gq程

5.3 nice
用于改变一个或多个q程的优先; 但只有root或提高进E的优先U? 普通用户只?
降低q程的优先.
nice用负数表C提高优先,而正数表明降低优先,通常此D围是-20~20.

如未指定提高优先U?nice会降低或不改变进E的优先U? 当然如果没有权限的话
q程的优先不会有Q何改?

一般情况下我们用nice来降低后台进E的优先U?默认优先Uؓ10).

nice find . -name "*.c" -print &
nice 16 find . -name "*.c" -print &

5.4 wait
wait PID

{待作业l束,参数为pid,在shell script中有时用?

5.5 nohup
nohup command &

5.6 sleep

sleep seconds

q程前后台切? Ctrl-Z, fg, bg


6. 通讯

6.1 ftp
6.2 mailx
6.3 minicom (串口l端,MODEM)

7. 文g比较
cmp
comm
diff (用于比较文本文g)
diff3 (比较3个文?
sdiff

8. 文g操作
touch 创徏文g,修改文g日期{?
chmod
chwon
chgrp
rm 慎用 rm -rf
mv Ud文g或改?
cp cp -r 复制目录
cat
rcp q程复制
ln 默认情况下ؓ连?每个文gh相同的inode
ln -s sourcefile targetfile

9. 目录操作
mkdir [-p] [-m mode] directory
rmdir [-p] directory

10. 文g信息命o
ls
find
最基本的功能是查找一个文件名或目录,常用格式如下Q?
find . -print (cM?ls -lR)

find可用如下属性进行查找:
-name 查找文g名,含通配W??的文件名用引hh
-perm 00x000 八进制文件属?
-atime n n天之前访问过的文?
-mtime n n天之间修改过的文?
-ctime n 文g的状态在n前之间修改过
-exec command 如命令的q回代码为零(扑ֈ相应的文?则真Qcommand必须?
\; l果Q此外在命o的执行中 {} 为查扑ֈ的文件\径名
-ok command 与exec相类|但在执行每个命o之间要求用户认
-print 打印当前路径?
-newer filename 如文件的最后修Ҏ(gu)期较filename新则为真
-type c c=[b,c,d,l,p,f]文gcd
-user username 如文件的属主为username则ؓ?
-nouser 文g属主?etc/passwd文g中不存在
-group grouname 文gl?

逻辑q算W: -a -o !

C列Q?
find $HOME \( -name a.out -o -name "*.o" \) -atime +7 -exec rm {} \;
find . -atime 0 -print
find / .name .profile -print
find . -perm 777 -a -mtime 7 -exec chmod 755 {} \;


file
more
less
tail (tail -f filename)
head
wc
read 用于shell~程
col
pg (SYSV)

11. ~辑?
vi
ed
joe

12. 文g内容查找
grep
egrep
正规表达? . * ^ $ + ? []

strings


13. d调度
at
atq 列出队列中的d
crontab

14. 存储,归纳及压~?
compress .Z
uncompress .Z
cpio
dd dd if=inputfile of=outputfile
dd if=boot.img of=/dev/fd0H1440
pack .z 30%-50%文本文g
pcat pact file.z
gzip .gz
gunzip
tar tar -[txc]vf targetfile [sourcefile]
tar -cvf target.tar sourcefilelist
tar -tvf target.tar [filename]
tar -xvf target.tar [filename]
GNU TAR:
tar -zcvf target.tar.gz sourcefilelist
tar -zxvf target.tar.gz [filelist]
tar -ztvf target.tar.gz [filelist]

zcat .Z

uuencode
uudecode

15. 其他命o
date
env
unix2dos (linux没有)
dos2unix
uname
uptime
free
time
top

16. 文本处理
cut
fmt 每行格式转化?2?用于邮g格式?
fold 折行处理,一行到多行,一般ؓ80?
join
paste
sort
tr
tr '\"' '' < file1

#!/bin/sh

for i in *
do
mv $i `echo $i |tr /[a-z]/[A-Z]/`
done

uniq 报告/删除文g中相同的复制?
sed 编辑器
sed 's/96/tt/' student.txt
awk
awk '{print $1" "$2}' sourcefile
awk -f class.awk student.txt > linux-student.txt
文gclass.awk内容如下Q?

#
#class.awk
#
BEGIN {printf "%-12s%s\n","班","学号 姓名";
printf "-------------------------------------------\n\n"}
/[1-9]+\B*$/ {class=$0}
/^9[5-8]+/ {printf "%-12s%s\n", class,$0 | "sort"}
#Enf of class.awk

awk -f traffic.awk traffic.txt
文gtraffic.awk内容如下Q?
#
#traffic.awk
#
{ if ( $2 < 10000 ) t_0 += $2;
if ( $2 > 10000 && $2 < 50000) t_10 += $2;
if ( $2 > 50000 && $2 < 100000) t_50 += $2;
if ( $2 > 100000) t_100 += $2;
total += $2 }
END {printf "t_0 = %dKB %5.2f\%\n",t_0,t0*100/total;
printf "t_10 = %dKB %5.2f\%\n",t_10,t10*100/total;
printf "t_50 = %dKB %5.2f\% \n",t_50,t_50*100/total;
printf "t_100 = %dKB %5.2f\%\n",t_100,t_100*100/total;
printf "Total = %dKB\n", total}

#End of traffic.awk


17. |络配置命o及故障排除命?
17.1 ifconfig
Interface Config , |卡配置命o, 相关文g:/proc/net/dev
详细使用说明: man ifconfig

CZ:
#ifconfig
lo Link encap:Local Loopback
|卡标识 装cd: 本地回环

inet addr:127.0.0.1 Bcast:127.255.255.255 Mask:255.0.0.0
IP地址:127.0.0.1 q播地址:127.255.255.255 子网掩码:255.0.0.0

UP BROADCAST LOOPBACK RUNNING MTU:3584 Metric:1
已启?接受q播 本地回环 正在q行 最大传输单? 3584 路由距离向量:1

RX packets:718 errors:0 dropped:0 overruns:0 frame:0
已接受数据包:718

TX packets:718 errors:0 dropped:0 overruns:0 carrier:0
已发送数据包:718

collisions:0
撞:0

eth0 Link encap:Ethernet HWaddr 00:80:C8:4C:6A:D0
|卡标识 装cd: Ethernet g(MAC)地址: 00:80:C8:4C:6A:D0

inet addr:202.118.66.81 Bcast:202.118.66.255 Mask:255.255.255.0
IP地址:202.118.66.81 q播地址:202.118.66.255 子网掩码:255.255.255.0

UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
已启?接受q播 正在q行 多点q播 最大传输单? 1500 路由距离向量:1

RX packets:13900 errors:0 dropped:0 overruns:0 frame:0
已接受数据包:13900

TX packets:5859 errors:0 dropped:0 overruns:0 carrier:0
已发送数据包:5859

collisions:0
撞:0

Interrupt:10 Base address:0xe400
中断(IRQ):10 端口地址: 0xe400

#ifconfig eth0 昄eth0的相关信?
#ifconfig -a 昄所有网l设备的配置信息
#ifconfig eth0 down Down掉eth0
#ifconfig eth0 202.118.66.81 broadcast 202.118.66.255 [up]
#ifconfig eth0 202.118.66.81 broadcast 202.118.66.255 netmask 255.255.255.0
#ifconfig eth0 up

17.2 route
路由表维护命? 相关文g: /proc/net/route

$ /sbin/route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
localnet * 255.255.255.0 U 0 0 49 eth0
192.168.1.0 * 255.255.255.0 U 0 0 655 eth1
192.168.2.0 * 255.255.255.0 U 0 0 498 eth2
192.168.3.0 * 255.255.255.0 U 0 0 825 eth3
127.0.0.0 * 255.0.0.0 U 0 0 13 lo
default olive.dlut.edu. 0.0.0.0 UG 1 0 4834 eth0

#route add default gw 202.118.66.1
#route add default gw 202.118.66.1 eth0
#/sbin/route add -net 202.118.68.0 netmask 255.255.252.0 gw 202.118.66.16
#/sbin/rouet del default 202.118.66.1
#/sbin/route del -net 202.118.68.0 netmask 255.255.252.0 gw 202.118.66.16


17.3 netstat
昄L当前路由? 相关文g: /proc/net/route
netstat -rn
/home/hbwork[102]netstat -rn

Routing Table:
Destination Gateway Flags Ref Use Interface
-------------------- -------------------- ----- ----- ------ ---------
202.118.70.27 202.118.66.16 UGHD 0 1
202.118.69.254 202.118.66.16 UGHD 0 1
202.118.68.243 202.118.66.16 UGHD 0 1
202.118.70.21 202.118.66.16 UGHD 0 0
202.118.71.10 202.118.66.16 UGHD 0 1
202.118.71.204 202.118.66.16 UGHD 0 1
202.118.68.160 202.118.66.16 UGHD 0 1
202.199.128.52 202.118.66.254 UGHD 0 2
202.118.68.66 202.118.66.16 UGHD 0 1
202.118.69.69 202.118.66.16 UGHD 0 1
202.118.69.228 202.118.66.16 UGHD 0 1
202.118.71.68 202.118.66.16 UGHD 0 1
202.118.70.37 202.118.66.16 UGHD 0 1
202.118.66.0 202.118.66.18 U 3 12259 hme0
224.0.0.0 202.118.66.18 U 3 0 hme0
default 202.118.66.1 UG 0 70354
127.0.0.1 127.0.0.1 UH 0 41316 lo0

Destionation: 目标|络或主?
Gateway: 下一个\?认ؓ距离目标较近的\qIP地址,在数据传送时发往
q一IP地址.
Flags:
U Router is up, 目标可达
H Specific router,到特定主机的路由
G 此\׃ؓ其他路由q行间接讉K到的,如果没有G标志则表明相应的
路由器或L是直接连接在相应的\由器上的.
D 此\由是ICMP协议的\径重定向信息所建立?
M 由ICMP之重定向信息所修改

REFS: 在此路由上现在正在用的链接?q些q接可能是由q箋旉较长的ftp?
telnetd, 每个使用tcp的服务或应用在执行时此列值均?.

Use: 自TCP/IP启动以来通过此\由器的数据包?

Interface: |卡逻辑?UNIX不同取名不同.


17.4 nslookup
Name Server Lookup, DNS服务器诊断工?
使用C列:
[hbwork@helius hbwork]$ nslookup www.dlut.edu.cn
Server: cedrus.dlut.edu.cn
Address: 202.118.66.6

Name: peony.dlut.edu.cn
Address: 202.118.66.18
Aliases: www.dlut.edu.cn

[hbwork@helius hbwork]$ nslookup
Default Server: cedrus.dlut.edu.cn
Address: 202.118.66.6

> www.dlut.edu.cn
Server: cedrus.dlut.edu.cn
Address: 202.118.66.6

Name: peony.dlut.edu.cn
Address: 202.118.66.18
Aliases: www.dlut.edu.cn
> set q=ns #查询相应域的DNS服务?
> dlut.edu.cn #输入要查询的域名
Server: cedrus.dlut.edu.cn #默认域名服务器ؓcedrus.dlut.edu.cn
Address: 202.118.66.6 #参?etc/resolv.conf文g

dlut.edu.cn nameserver = gingko.dlut.edu.cn
dlut.edu.cn nameserver = olive.dlut.edu.cn
dlut.edu.cn nameserver = cedrus.dlut.edu.cn
gingko.dlut.edu.cn internet address = 202.118.66.8
olive.dlut.edu.cn internet address = 202.118.68.1
olive.dlut.edu.cn internet address = 202.118.69.1
olive.dlut.edu.cn internet address = 202.118.70.1
olive.dlut.edu.cn internet address = 202.118.71.1
olive.dlut.edu.cn internet address = 202.118.66.16
cedrus.dlut.edu.cn internet address = 202.118.66.6

> dl.lnpta.net.cn #查询dl.lnpta.net.cn的域名服务器
Server: cedrus.dlut.edu.cn
Address: 202.118.66.6

Non-authoritative answer:
dl.lnpta.net.cn nameserver = ns.lnpta.net.cn

Authoritative answers can be found from:
ns.lnpta.net.cn internet address = 202.96.64.68

> server ns.lnpta.net.cn
Default Server: ns.lnpta.net.cn
Address: 202.96.64.68

server: ns.lnpta.net.cn
Address: 202.96.64.68

Non-authoritative answer:
www.dlut.edu.cn canonical name = peony.dlut.edu.cn
> dlut.edu.cn #查询域dlut.edu.cn的MX记录
Server: ns.lnpta.net.cn
Address: 202.96.64.68

Non-authoritative answer:
dlut.edu.cn preference = 1, mail exchanger = gingko.dlut.edu.cn

Authoritative answers can be found from:
dlut.edu.cn nameserver = gingko.dlut.edu.cn
dlut.edu.cn nameserver = CEDRUS.dlut.edu.cn
dlut.edu.cn nameserver = olive.dlut.edu.cn
gingko.dlut.edu.cn internet address = 202.118.66.8
CEDRUS.dlut.edu.cn internet address = 202.118.66.6
olive.dlut.edu.cn internet address = 202.118.71.1
olive.dlut.edu.cn internet address = 202.118.66.16
olive.dlut.edu.cn internet address = 202.118.68.1
olive.dlut.edu.cn internet address = 202.118.69.1
olive.dlut.edu.cn internet address = 202.118.70.1
> exit

17.5 ping
TCP/IP ICMP(Internet Control Message Protocol)诊断工具

ping [hostname|IpAddress]

Error Message: host unreachable
network unreachable

[hbwork@helius hbwork]$ ping 202.118.66.1
PING 202.118.66.1 (202.118.66.1): 56 data bytes
64 bytes from 202.118.66.1: icmp_seq=0 ttl=255 time=23.1 ms
64 bytes from 202.118.66.1: icmp_seq=1 ttl=255 time=2.1 ms
64 bytes from 202.118.66.1: icmp_seq=2 ttl=255 time=1.9 ms

--- 202.118.66.1 ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 1.9/9.0/23.1 ms

17.6 hostname
昄或设|主机名

17.7 domainname
昄或设|主机域?

17.8 traceroute
Windows 95: tracert

traceroute hostname
traceroute destionation_ip_address
17.9 arp
昄或设|相应主?ip地址的mac地址
相关文g: /proc/net/arp
cat /proc/net/arp

$arp hostname
$arp -a
$arp ip_address

昄或设|主机名需要root权限
#arp -s hostname eth_address [temp] [pub]
#arp -d hostname
#arp -d ip_address
#arp -f mac_ip_map_file 常用文g名ؓ/etc/ether
 



大鱼 2009-03-13 23:10 发表评论
]]>
վ֩ģ壺 | ׿| ׶| üɽ| ư| | | | | Ϫ| | Ҧ| | ຣʡ| | | | | ¡| ɽ| | | | | | ɽ| Ͽ| | ̶| ʡ| | Ľ| | | | Ӧñر| ˹| ϳ| | Ӣ| γ|