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/messagesfile. -
lsof -i :80: This displays the processes that are using the port80. -
lsof -u user1: This displays the files that are opened by theuser1user. -
lsof -c sshd: This displays the files that are opened by thesshdcommand. -
lsof -p 1234: This displays the files that are opened by the process with ID1234. -
lsof -i [email protected]:22: This displays the processes that are using the22port for the IP address192.168.1.10. -
lsof -i udp:53: This displays the processes that are using the53port for UDP connections.
Leave a Reply