lsof-command ¶
Linux lsof commands that will save Devops engineers hours of debugging.
-
Find what's using a specific port
$ lsof -i :5000
Shows which process is listening on port 5000. -
List all network connections
$ lsof -i
Shows all processes with active network connections. -
Find all files opened by a user
$ lsof -u username
Lists every file a specific user has open. -
Find what files a process is using
$ lsof -p 1234
Shows all files opened by process ID 1234. -
Find which process is using a file
$ lsof /var/log/syslog
Shows which process has this file open. -
List all TCP connections
$ lsof -i TCP
Shows only TCP network connections. -
Find all UDP connections
$ lsof -i UDP
Shows only UDP network connections. -
List files opened by a specific command
$ lsof -c nginx
Shows all files opened by nginx processes. -
Find deleted files still using disk space
$ lsof | grep deleted
Shows deleted files that processes still have open (eating disk space). -
List all IPv4 connections
$ lsof -i 4
Shows only IPv4 network connections. -
Find who's accessing a directory
$ lsof +D /var/log
Shows all processes accessing files in this directory. -
Monitor network activity in real-time
$ lsof -i -r 2
Refreshes every 2 seconds showing live network connections.
Pro tip: Combine multiple flags for powerful debugging:
$ lsof -u root -i TCP:80
Shows all port 80 connections by root user.
Save this post. You'll need it during your next production incident.
评论
请登录后发表评论。
暂无评论。成为第一个评论者!