Hongmu Notes

lsof

List open files and corresponding processes. NOTE: Listing files opened by others requires root privileges (or sudo)

100% Browser local processing 0 Data upload

Common examples

Find the process that has a given file open

lsof {{路径/到/文件}}

Find processes that have local internet ports open

lsof -i :{{端口}}

Print only the process ID (PID)

lsof -t {{路径/到/文件}}

List files opened by a given user

lsof -u {{用户名}}

List files opened by a given command or process

lsof -c {{进程或命令的名称}}

List files opened by a specific process (given its PID)

lsof -p {{pid}}

List open files in a directory

lsof +D {{路径/到/目录}}

Finds processes listening on local IPv6 TCP ports, without translating network or port numbers

lsof -i6TCP:{{端口}} -sTCP:LISTEN -n -P

Tip: curly braces{{…}}It is the parameter that needs to be replaced (path, file name, etc.); the command is only executed in the local terminal, and this site does not save any input.

English original text comparison

Expand English instructions and examples (source tldr-pages)

List open files and the corresponding processes. Note: Root privileges are required to list files opened by others. More information

Find the processes that have a given file open

lsof {{path/to/file}}

Find the process that opened a local internet port

lsof -i :{{port}}

Only output the process ID (PID)

lsof -t {{path/to/file}}

List files opened by the given user

lsof -u {{username}}

List files opened by the given command or process

lsof -c {{process_or_command_name}}

List files opened by a specific process, given its PID

lsof -p {{process_id}}

List open files in a directory

lsof +D {{path/to/directory}}

Find the process that is listening on a local IPv6 TCP port and don't convert network or port numbers

lsof -i6TCP:{{port}} -sTCP:LISTEN -n -P

command information

command namelsof
PurposeList open files and corresponding processes. NOTE: Listing files opened by others requires root privileges (or sudo)
Applicable platforms通用
Number of examples8 Article
Official documentationhttps://manned.org/lsof
Data sourcetldr-pages(CC-BY-4.0)· Community Chinese Translation

FAQ

lsof What does the command do?

List open files and corresponding processes. NOTE: Listing files opened by others requires root privileges (or sudo)

lsof How to use it?

Pages listed by scene8Commonly used examples: Each example first explains the purpose, and then gives a complete command that can be directly copied (the parameters that need to be replaced are in the curly brackets).

lsof What are the most commonly used operations?

Find the process that has a given file open:lsof {{路径/到/文件}}

What do the curly braces in the command mean?

curly braces{{…}}Indicates that you need to replace it with your own value, such as path and file name; square brackets for parameters with the same name (such as[-C|--directory]) indicates optional writing.