lsof, short for “list open files”, is used to list detailed information about files that are currently opened by processes.

Basic Syntax

lsof [options] [files or directories]

  • options: This specifies the options for the command.
  • files or directories: This specifies the files or directories for which to display open files.

Commonly Used Options

  • -i: This shows information about files opened by Internet connections.
  • -u: This shows information about files opened by a specific user.
  • -p: This shows information about files opened by a specific process ID.
  • -c: This shows information about files opened by a specific command name.
  • -t: This shows only the process IDs of files being used.
  • -n: This prevents the conversion of network numbers to hostnames.
  • -F: This formats the output of the command.
  • -X: This shows more verbose output.

Useful Examples

  • lsof /var/log/messages: This displays the processes that have opened the /var/log/messages file.
  • lsof -i :80: This displays the processes that are using the port 80.
  • lsof -u user1: This displays the files that are opened by the user1 user.
  • lsof -c sshd: This displays the files that are opened by the sshd command.
  • lsof -p 1234: This displays the files that are opened by the process with ID 1234.
  • lsof -i [email protected]:22: This displays the processes that are using the 22 port for the IP address 192.168.1.10.
  • lsof -i udp:53: This displays the processes that are using the 53 port for UDP connections.

Leave a Reply

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

Comments

  1. […] Once installed, let’s first allow TCP traffic over your SSH port so that you don’t get locked out of…

  2. […] have the option to choose between Password and SSH key selection. Learn more about SSH keys here. It’s recommended…