lsof

lsof is one of the little known but very powerfull utility in Linux. Man pages basically says that lsof: list open files. But you can use it for managing and tracking network connections, you can list open ports, identify connections currently being made to your system, and determine what resources a process is using. Not only that, but you can also determine what processes a particular user has and find detailed information about file and directory usage. Here some example usages:

List all open files in system:
lsof

List all network connections:
lsof -i

List all UDP connections:
lsof -iUDP

List connections on specific port number:
lsof -i :80

List connections on specific host:
lsof [email protected]

List connection on specifics host and port:
lsof [email protected]:80

List all files opened by user fred:
lsof -u fred

List all files which opened by specific command:
lsof -c mysqld

List all process which using a specific file:
lsof /var/run/mysqld/mysqld.sock

List all processes which opens files under specific directory:
lsof +d /etc/passwd

List all the open files used by a specific process with process id:
lsof -p 8729

Leave a Reply

Your email address will not be published. Required fields are marked *