免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1617 | 回复: 0
打印 上一主题 下一主题

UNIX系统常用命令 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-08-31 11:58 |只看该作者 |倒序浏览
UNIX系统常用命令
UNIX系统常用命令
UNIX系统常用命令格式:
command [flags] [argument1] [argument2] ...
其中flags以-开始,多个flags可用一个-连起来,如ls -l -a 与ls -la相同。
根据命令的不同,参数分为可选的或必须的;所有的命令从标准输入接受输入,输出
结果显示在标准输出,而错误信息则显示在标准错误输出设备。可使用重定向功能对
这些设备进行重定向。
命令在正常执行结果后返回一个0值,如果命令出错可未完全完成,则返回一个
非零值(在shell中可用变量$?查看). 在shell script中可用此返回值作为控制逻辑
的一部分。
注:不同的UNIX版本的flags可能有所不同。
1、与用户相关的命令
1.1 login
(在LINUX Redhat下此命令功能与Solaris/BSD不同,执行login会退出当前任务).
login:
Password:
相关文件:
在下面的这些文件中设定shell运行时必要的路径,终端类型,其他变量或特殊程序.
$HOME/.profile (Bourne shell, sh, bash)
$HOME/.cshrc (csh, tcsh)
$HOME/.tcshrc (tcsh)
/etc/passwd文件中列出每个用户的shell
/etc/csh.cshrc
/etc/csh.login
/etc/profile (Bourne shell, bash)
/etc/login (Bourne shell, bash)
csh: /etc/csh.cshrc和$HOME/.cshrc每次执行都会读取,
而/etc/csh.login和$HOME/.login只有注册shell才执行
修改相应文件后使用 source .cshrc使能相关修改,如果修改了path则
还需使用rehash刷新可执行文件hash表。
tcsh: $HOME/.tcshrc, 没有些文件读取.cshrc
sh: /etc/profile和$HOME/.profile注册shell
bash: /etc/profile和$HOME/.bash_profile注册shell读取
.bashrc交互式非注册shell才读取。
在sh/bash下手工执行相关文件:
. /etc/profile
相关文件执行顺序
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 新建文件或目录的保护属性
(3)TERM
(4)切忌PATH中加入 .
1.2. rlogin
与telnet类似,连接到远程主机.
rlogin remotehost [ -l loginname ]
Or:
rsh [-l loginname] remotehost [command ]
相关文件:
远程主机的 /etc/hosts.equiv 和 $HOME/.rhosts
相关网络配置文件:
/etc/inetd.conf文件中的r系统服务.Redhat下为shell, login, exec, 对应
的网络守护进程(daemon)为in.rshd, in.rlogind, in.rexecd.
建议: 从安全角度出发,关闭r系列服务.
1.3. telnet
telnet remotehost [port]
相关文件:
/etc/inetd.conf文件中的telnet服务.
/etc/issue.net
TIPS: strings /usr/sbin/in.telnetd |egrep issue
1.4. passwd 更改口令
1.5 exit 退出当前shell
2. 命令或文件的查找
相关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内带命令
[hbwork@toshiba]$ which which
which: shell built-in command.
2.2 where(tcsh)
Syntax: where command
2.3 locate (LINUX)
Syntax: locate filename
相关命令: updatedb更改locate文件名数据库
3. 查看命令的用法
man
相关文件:
/etc/man.config
4. 管理员常用命令
4.1 install
用于安装一个新的命令或daemon等. 一般情况下可以不用,但很多软件在其安装
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
关机,在多用户方式下(Runlevel 3)不建议使用,
4.4 ulimit
korn shell和bourne shell中可用此命令,在csh系列中相应的命令为limit.
用于限制每个进程可使用的系统资源,通常分两种限制:
. Hard limits 系统所定义的资源,只有root能更改
. 软限制 对新建进程所使用的限制,可增加到系统的Hard Limit.
Flags:
-a 列出软限制
-Ha 列出Hard Limit
-c size 设置coredump size的块大小
-t size cputime
-f size file size
4.5 umask 系统管理员用于设置用户默认的umask值.
5.与进程相关的命令
进程基本概念: 进程与命令的执行相关,但并不是一一对应; 一条命令可能对应若干
个进程(如shell script, pipe等).但最简单的命令与umask只有一个进程.
进程分类:
.交互式进程:可以前台或后台执行,前后台可切换
.批处理进程:不通过终端提交,一般将它们放在任务队列中顺序执行. 如通过
at 和 crontab提交的任务.
.deamon:永不终止的进程,等待响应来自其他进程的服务请求.如sendmail,
named(DNS), POP3及apache等.
进程的相关属性:
PID
Real UID
Effective UID (SUID)
Real GID
Effective GID (SGID)
Priority(Nice Number)执行的优先级
5.1 ps
Process Status, 列出当前运行的进程状态,根据选项不同,可列出所有的或部分进程
. 无选项时只列出从当前终端上启动的进程(SYSV)或当前用户($USER)的进程(BSD),
不同的UNIX版本之间有差别. linux使用BSD版本的ps
. BSD版本ps命令使用方法:
ps
ps aux 列出系统中所有的进程的详细情况
ps aux |egrep inetd
输出信息内容:
PID
Terminal 如无相应终端则为-
cpu time
UserID or Username
进程启动时间或日期
进程状态(Stat: S(leep) R(unnable) D(uninterrupt sleep) Z(ombie)
W 进程没有驻留页面, N: 进程的nice值为负值
5.2 kill
kill [-signal] PID
kill -l 列出可用信号量
常用信息量:
-HUP (1) 重启进程
ps ax |egrep inetd
kill -HUP pid_of_inetd
-KILL (9) 强制中止
PID取值含义:
>0 指特定进程(实际进程)
=0 同组用户的所有process(PGID)
=-1 Effective UID = 执行命令用户之uid
linux-student.txt
文件class.awk内容如下:
#
#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
文件traffic.awk内容如下:
#
#traffic.awk
#
{ if ( $2  10000 && $2  50000 && $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. 网络配置命令及故障排除命令
17.1 ifconfig
Interface Config , 网卡配置命令, 相关文件:/proc/net/dev
详细使用说明: man ifconfig
示例:
#ifconfig
lo Link encap

ocal Loopback
网卡标识 封装类型: 本地回环
inet addr:127.0.0.1 Bcast:127.255.255.255 Mask:255.0.0.0
IP地址:127.0.0.1 广播地址:127.255.255.255 子网掩码:255.0.0.0
UP BROADCAST LOOPBACK RUNNING MTU:3584 Metric:1
已启动 接受广播 本地回环 正在运行 最大传输单元: 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

0
网卡标识 封装类型: Ethernet 硬件(MAC)地址: 00:80:C8:4C:6A

0
inet addr:202.118.66.81 Bcast:202.118.66.255 Mask:255.255.255.0
IP地址:202.118.66.81 广播地址:202.118.66.255 子网掩码:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
已启动 接受广播 正在运行 多点广播 最大传输单元: 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 显示所有网络设备的配置信息
#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
路由表维护命令, 相关文件: /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
显示主机当前路由表, 相关文件: /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: 下一个路由,认为距离目标较近的路由的IP地址,在数据传送时将发往
这一IP地址.
Flags:
U Router is up, 目标可达
H Specific router,到特定主机的路由
G 此路由为其他路由进行间接访问到的,如果没有G标志则表明相应的
路由器或主机是直接连接在相应的路由器上的.
D 此路由是ICMP协议的路径重定向信息所建立的.
M 由ICMP之重定向信息所修改
REFS: 在此路由上现在正在使用的链接数,这些连接可能是由连续时间较长的ftp或
telnet任务, 每个使用tcp的服务或应用在执行时此列值均加1.
Use: 自TCP/IP启动以来通过此路由器的数据包量.
Interface: 网卡逻辑名,UNIX不同取名不同.
17.4 nslookup
Name Server Lookup, DNS服务器诊断工具
使用示列:
[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文件
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地址
相关文件: /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 常用文件名为/etc/ether

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/20110/showart_371735.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP