Linux操作系统实用技巧精彩汇集

http://tech.ddvip.com   2007年08月31日    社区交流

内容摘要:因为用Linux的时间越来越长,所需要做的事也越来越多,效率成了我必需突破的瓶颈。在此总结一下这段时间用过的一些好的Linux技巧。以后时常补充这样自己要用的时候就很方便了。

  lsof -g gid 显示归属 gid 的进程情况

  lsof +d /usr/local/ 显示目录下被进程开启的文件

  lsof +D /usr/local/ 同上,但是会搜索目录下的目录,时间较长

  lsof -d 4 显示使用 fd 为4 的进程

  lsof -i [i] 用以显示符合条件的进程情况

  语法: lsof -i[46] [protocol][@hostname|hostaddr][:service|port]

  46 --> IPv4 or IPv6

  protocol --> TCP or UDP

  hostname --> Internet host name

  hostaddr --> IPv4 位置

  service --> /etc/service中的 service name (可以不止一个)

  port --> 端口号(可以不止一个)

  例子: TCP:25 - TCP and port 25

  @1.2.3.4 - Internet IPv4 host address 1.2.3.4

  tcp@ohaha.ks.edu.tw:ftp - TCP protocol host:ohaha.ks.edu.tw service name:ftp

  lsof -n 不将 IP转换为 hostname,预设是不加上-n参数

  例子: lsof -i tcp@ohaha.ks.edu.tw:ftp -n

  lsof -p 12 看进程号为 12的进程打开了哪些文件

  2、grep 不显示本身进程

  #ps -aux|grep httpd|grep -v grep

  grep -v grep可以取消显示你所执行的 grep 本身这个进程,-v 参数是不显示所列出的进程名

  3、查看本机IP

  ifconfig |grep "inet" |cut -c 0-36|sed -e 's/[a-zA-Z: ]//g'

  hostname –i

  4、查看有多少活动的Httpd进程

  #!/bin/sh

  while (true)

  do

  pstree |grep "*[httpd]$"|sed 's/.*-([0-9][0-9]*)*[httpd]$/1/'

  sleep 3

  done

  同样可以引用到其它的进程

  5、设置 com1口,让超级终端通过 com1口进行登录

责编:豆豆技术应用

正在加载评论...