⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unix系统常用命令.htm

📁 台大计中UNIX讲义
💻 HTM
📖 第 1 页 / 共 2 页
字号:
        正规表达式:  . * ^ $ + ? []

   strings
   

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

14. 存储,归纳及压缩
    compress   .Z
    uncompress .Z
    cpio
    dd    dd if=inputfile of=outputfile
          dd if=boot.img of=/dev/fd0H1440
    pack  .z  30%-50%文本文件
    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. 其他命令
    date
    env
    unix2dos (linux没有)
    dos2unix
    uname
    uptime
    free
    time
    top

16. 文本处理
    cut
    fmt  每行格式转化为72列,用于邮件格式化
    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 报告/删除文件中相同的复制行
    sed  流编辑器
        sed 's/96/tt/' student.txt
    awk
        awk '{print $1" "$2}' sourcefile
        awk -f class.awk student.txt > 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 )   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. 网络配置命令及故障排除命令
17.1 ifconfig
     Interface Config , 网卡配置命令, 相关文件:/proc/net/dev
     详细使用说明: man ifconfig

示例:
#ifconfig 
lo        Link encap:Local 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:D0  
网卡标识  封装类型: Ethernet   硬件(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   广播地址: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

--
※ 来源:.碧海青天 bbs.dlut.edu.cn.[FROM: apple.dlut.edu.c]
</PRE></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -