linux shell 命令大全(三)

3、bzip2根式命令

  功能:bzip2格式压缩命令,

  注意:生成的文件会把源文件覆盖

  bzip2   <filename>

  bunzip2 <filename>

  例如:

  # bzip2 a.sh

  # ll

  -rwxr-xr-x    1 root     root           85 12月 18 21:08 a.sh.bz2

  # bunzip2 a.sh.bz2

  # ll

  -rwxr-xr-x    1 root     root           48 12月 18 21:08 a.sh

  4、tar命令

  功能:归档、压缩等,比较重要,会经常使用。

  -cvf  <DSTfilename.tar> <SRCfilename> 压缩文件或目录

  -xvf  <SRCfilename>   解压缩文件或目录

  -zcvf  <DSTfilename> <SRCfilename> 压缩文件或,格式tar.gz

  -zxvf  <DSTfilename> <SRCfilename> 解压缩文件或,格式tar.gz

  -zcvf  <DST.tgz> <SRCfilename>  压缩文件或,格式tgz

  -zxvf  <DST.tgz> <SRCfilename>  解压缩文件或,格式tgz

  举例:

  # tar cvf abc.tar *.sh

  # tar xvf abc.tar

  # tar czvf abc.tar.gz *.sh

  # ll

  -rw-r–r–    1 root     root        20480  5月 21 10:50 abc.tar

  -rw-r–r–    1 root     root         1223  5月 21 10:53 abc.tar.gz

  # tar xzvf abc.tar.gz

  八、网络相关命令

  1、ifconfig命令

  功能:显示修改网卡的信息

  ifconfig  显示网络信息

  ifconfig eth0 显示eth0网络信息

  修改网络信息:

  ifconfig eth0 192.168.1.1 netmask 255.255.255.0 设置网卡1的地址192.168.1.1,掩码为255.255.255.0

  ifconfig eth0:1 192.168.1.2    捆绑网卡1的第二个地址为192.168.1.2

  ifconfig eth0:x 192.168.1.n    捆绑网卡1的第n个地址为192.168.1.n

  例如:

  # ifconfig eth0:1 192.168.1.11

  # ifconfig

  eth0      Link encap:Ethernet  HWaddr 00:0C:29:06:9C:24

  inet addr:192.168.1.5  Bcast:192.168.1.255  Mask:255.255.255.0

  UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

  RX packets:4220 errors:0 dropped:0 overruns:0 frame:0

  TX packets:3586 errors:0 dropped:0 overruns:0 carrier:0

  collisions:0 txqueuelen:1000

  RX bytes:342493 (334.4 Kb)  TX bytes:469020 (458.0 Kb)

  Interrupt:9 Base address:0×1400

  eth0:1    Link encap:Ethernet  HWaddr 00:0C:29:06:9C:24

  inet addr:192.168.1.11  Bcast:192.168.1.255  Mask:255.255.255.0

  UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

  Interrupt:9 Base address:0×1400

  2、route命令

  功能:显示当前路由设置情况

  route 显示当前路由设置情况,比较慢一般不用。

  route add -net 10.0.0.0 netmask 255.255.0.0 gw 192.168.1.254  添加静态路由

  route del -net 10.0.0.0 netmask 255.255.0.0 gw 192.168.1.254  添加静态路由

  route add default gw 192.168.1.1 metric1    设置192.168.1.1为默认的路由

  route del default       将默认的路由删除

  举例:

  # route add -net 10.0.0.0 netmask 255.255.0.0 gw 192.168.1.254

  # netstat -nr

  Kernel IP routing table

  Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface

  192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0

  10.0.0.0        192.168.1.254   255.255.0.0     UG        0 0          0 eth0

  169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth0

  0.0.0.0         192.168.1.254   0.0.0.0         UG        0 0          0 eth0

  # route del -net 10.0.0.0 netmask 255.255.0.0 gw 192.168.1.254

  # netstat -nr

  Kernel IP routing table

  Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface

  192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0

  169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth0

  0.0.0.0         192.168.1.254   0.0.0.0         UG        0 0          0 eth0

  3、netstat命令

  功能:显示网络状态

  netstat -an  查看网络端口信息

  netstat -nr 查看路由表信息,比route快多了,

  4、启动网络的命令

  redhat族的命令:

  /etc/init.d/network

  debian命令:

  /etc/init.d/networking

  例如:

  /etc/init.d/network stop 停止网络,

  /etc/init.d/network start 启动网络,

  5、手工修改网络配置

  (1)、debian系统

  配置文件位置为:/etc/network/interfaces

  # The loopback network interface

  auto lo

  iface lo inet loopback

  # The primary network interface

  auto eth0 eth1

  iface eth0 inet static

  address 10.4.5.6

  netmask 255.255.255.0

  network 10.4.5.0

  broadcast 10.4.5.255

  iface eth1 inet static

  address 219.25.5.60

  netmask 255.255.255.192

  network 219.25.5.0

  broadcast 219.25.5.63

  gateway 219.25.5.30

  修改后保存配置后,运行

  /etc/init.d/networking restart

  网络配置就改变了

  (2)、redhat系统

  配置文件位置为:/etc/sysconfig/network-scripts/ifcfg-eth0

  DEVICE=eth0

  BOOTPROTO=static

  BROADCAST=192.168.1.255

  IPADDR=192.168.1.5

  NETMASK=255.255.255.0

  NETWORK=192.168.1.0

  GATEWAY=192.168.1.254

  ONBOOT=yes

  TYPE=Ethernet

  修改后保存配置后,运行

  /etc/init.d/network restart

  或者

  service network restart

  网络配置就改变了。

  默认DNS的文件的位置为:/etc/resolv.conf

  #cat /etc/resolv.conf

  search test.com.cn

  nameserver 192.168.1.11

  6、网络排错

  (1)、ping命令

  功能:不说了,不知道就用干这行了。

  ping www.163.com

  (2)、traceroute命令

  功能:路由跟踪

  traceroute www.163.com

  traceroute 207.68.173.7

  (3)、nslookup命令

  功能:域名解析排错

  例如:

  $ nslookup

  Note:  nslookup is deprecated and may be removed from future releases.

  Consider using the `dig’ or `host’ programs instead.  Run nslookup with

  the `-sil[ent]‘ option to prevent this message from appearing.

  > www.dlut.edu.cn

  Server:         192.168.1.11

  Address:        192.168.1.11#53

  Non-authoritative answer:

  Name:   www.dlut.edu.cn

  Address: 202.118.66.66

  > server 202.118.66.6

  Default server: 202.118.66.6

  Address: 202.118.66.6#53

  > www.baidu.com

  Server:         202.118.66.6

  Address:        202.118.66.6#53

  Non-authoritative answer:

  www.baidu.com   canonical name = www.a.shifen.com.

  Name:   www.a.shifen.com

  Address: 202.108.22.5

  九、其他命令

  1、ssh命令

  功能:远程登陆到其他UNIX主机

  ssh -l user1 192.168.1.2 使用用户名user1登陆到192.168.1.2

  ssh [email protected]   使用用户名user1登陆到192.168.1.2

  2、scp命令

  功能:安全copy

  例如:

  scp abc.tar.gz [email protected]:~ 将本地的abc.tar.gz 复制到 192.168.1.5的user1用户的根(/home/user1)下。

  3、telnet命令

  功能:登陆到远程主机

  例如:

  telnet 192.168.1.5

猜你喜欢

转载自lzj0470.iteye.com/blog/858055