lsof

Send to Kindle
home » snippets » linux » lsof


Notes

# Show all network connections
lsof -i

# Show only TCP connections
lsof -i TCP

# What's using port 22?
# Note: use sudo to see root processes
sudo lsof -i :22
sudo lsof -i TCP:22

# What does process 1234 have open?
lsof -F -p 1234 | less

# What's command foo using?
lsof -c foo

# What's using some file? (e.g. /var/log/messages)
lsof /var/log/messages

# What do I have open?
# Long output!
lsof -u $USER

# Want just the PID?  Then use -t
lsof -t -c Mail

kill -HUP `lsof -t -c sshd`
# Kill everything I have open.
kill -9 `lsof -t -u $USER`


# Combine conditions using -a
lsof -a -u $USER -i @1.1.1.1

# Show open files that have a link count less than 1!
lsof +L1