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

发表于:2011-4-15 10:02

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:korn    来源:51Testing软件测试网采编

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

  [管理与网络]

  1、 lsof 用法小全

  lsof abc.txt 显示开启文件 abc.txt 的进程

  lsof -i :22 知道 22 端口现在运行什么程序

  lsof -c nsd 显示 nsd 进程现在打开的文件

  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 -itcp@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

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

61/6123456>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号