Difference between revisions of "Lsof"

From wikieduonline
Jump to navigation Jump to search
 
(20 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<code>lsof</code><ref>http://man7.org/linux/man-pages/man8/lsof.8.html</ref> list open files and [[network]] connections.
+
{{lc}}
 +
<code>[[wikipedia:lsof]]</code><ref>http://man7.org/linux/man-pages/man8/lsof.8.html</ref> list open files and [[network]] connections.
  
  
 
== Basic commands ==
 
== Basic commands ==
 +
*  <code>lsof /path/to/file</code> or <code>lsof /path/to/dir</code> or <code>lsof [[/dev/]]sdc1</code>
 
*  <code>lsof -t /path/to/file</code>
 
*  <code>lsof -t /path/to/file</code>
<code>lsof /path/to/file</code> or <code>lsof /path/to/dir</code>
+
::<code>-t</code> terse output with process identifiers only and no header
 +
 
 +
=== Files related ===
 
List all open files by a specific process:
 
List all open files by a specific process:
*  <code>lsof -p PID</code>
+
*  <code>[[lsof -p]] PID</code>
 
 
 
*  <code>lsof -u USERNAME</code>
 
*  <code>lsof -u USERNAME</code>
 +
* <code>lsof -a +L1 /path/to/fs</code> (shows open, [[unlinked]] files) or <code>[[lsof -nP]] | grep '(deleted)'</code>
 +
* [[lsof +D /path/to/dir]]
  
 
=== Network related ===
 
=== Network related ===
* <code>lsof -i</code><ref>https://www.thegeekstuff.com/2012/08/lsof-command-examples/</ref>
+
* <code>[[lsof -i]]</code> <ref>https://www.thegeekstuff.com/2012/08/lsof-command-examples/</ref>
 
Open [[TCP]] ports:  
 
Open [[TCP]] ports:  
* <code>lsof -iTCP -sTCP:LISTEN -P -n</code>
+
* <code>[[lsof -iTCP -sTCP:LISTEN -P -n]]</code>
 
Open [[UDP]] ports:
 
Open [[UDP]] ports:
 
* <code>lsof -iUDP -P -n</code>
 
* <code>lsof -iUDP -P -n</code>
  
 +
* [[macOS]]: <code>sudo lsof -iTCP -sTCP:LISTEN -n -P</code>
  
 
== Related commands ==
 
== Related commands ==
Line 22: Line 28:
 
* <code>[[proc]]</code>
 
* <code>[[proc]]</code>
 
* <code>[[fuser]]</code>
 
* <code>[[fuser]]</code>
 +
* <code>lsof /dev/[[pts]]/*</code>
 +
* <code>[[lsof -Pnl +c0 +M -i4]]</code>
  
 
== Activities ==
 
== Activities ==
 
# Read <code>lsof</code> questions on StackExchange: https://unix.stackexchange.com/questions/tagged/lsof?tab=Votes
 
# Read <code>lsof</code> questions on StackExchange: https://unix.stackexchange.com/questions/tagged/lsof?tab=Votes
 
# Review further examples in https://www.thegeekstuff.com/2012/08/lsof-command-examples/
 
# Review further examples in https://www.thegeekstuff.com/2012/08/lsof-command-examples/
 +
# Read https://www.akadia.com/services/lsof_quickstart.txt
  
 
== See also ==
 
== See also ==
 
* {{lsof}}
 
* {{lsof}}
* <code>[[kill]]</code>
+
* {{kill}}
 
* {{Linux networking commands}}
 
* {{Linux networking commands}}
 
* {{files}}
 
* {{files}}

Latest revision as of 16:17, 11 February 2024

wikipedia:lsof[1] list open files and network connections.


Basic commands[edit]

  • lsof /path/to/file or lsof /path/to/dir or lsof /dev/sdc1
  • lsof -t /path/to/file
-t terse output with process identifiers only and no header

Files related[edit]

List all open files by a specific process:

Network related[edit]

Open TCP ports:

Open UDP ports:

  • lsof -iUDP -P -n
  • macOS: sudo lsof -iTCP -sTCP:LISTEN -n -P

Related commands[edit]

Activities[edit]

  1. Read lsof questions on StackExchange: https://unix.stackexchange.com/questions/tagged/lsof?tab=Votes
  2. Review further examples in https://www.thegeekstuff.com/2012/08/lsof-command-examples/
  3. Read https://www.akadia.com/services/lsof_quickstart.txt

See also[edit]

  • http://man7.org/linux/man-pages/man8/lsof.8.html
  • https://www.thegeekstuff.com/2012/08/lsof-command-examples/
  • Advertising: