生存指南 [英] lsof survival guide

查看:102
本文介绍了生存指南的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

lsof是用于unix系统的功能强大的命令行实用程序.它列出了打开的文件,并显示有关它们的信息.而且由于大多数内容都是在UNIX系统上的文件,因此lsof可以为系统管理员提供大量有用的诊断数据.

lsof is an increadibly powerful command-line utility for unix systems. It lists open files, displaying information about them. And since most everything is a file on unix systems, lsof can give sysadmins a ton of useful diagnostic data.

使用lsof的最常用和有用的方法有哪些?为此使用了哪些命令行开关?

What are some of the most common and useful ways of using lsof, and which command-line switches are used for that?

推荐答案

显示与给定port相关的所有联网:

To show all networking related to a given port:

lsof -iTCP -i :port
lsof -i :22

要显示与特定主机的连接,请使用@host

To show connections to a specific host, use @host

lsof -i@192.168.1.5

使用@host:port显示基于主机和端口的连接 lsof -i@192.168.1.5:22

Show connections based on the host and the port using @host:port lsof -i@192.168.1.5:22

grep ping LISTEN显示系统正在等待哪些端口的连接:

grepping for LISTEN shows what ports your system is waiting for connections on:

lsof -i| grep LISTEN

使用-u显示给定用户已打开的内容:

Show what a given user has open using -u:

lsof -u daniel

查看命令与-c一起使用的文件和网络连接

See what files and network connections a command is using with -c

lsof -c syslog-ng

通过-p开关,您可以查看给定进程ID已打开的内容,这对于了解有关未知进程的更多信息非常有用:

The -p switch lets you see what a given process ID has open, which is good for learning more about unknown processes:

lsof -p 10075

-t选项仅返回PID

lsof -t -c Mail

同时使用-t-c选项,您可以HUP进程

Using the -t and -c options together you can HUP processes

kill -HUP $(lsof -t -c sshd)

您还可以将-t-u一起使用,以杀死用户打开的所有内容

You can also use the -t with -u to kill everything a user has open

kill -9 $(lsof -t -u daniel)

这篇关于生存指南的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆