1 # List all open files
   2 lsof
   3 
   4 # Processes using a file? (fuser equivalent)
   5 lsof /path/to/file
   6 
   7 # Open files within a directory
   8 lsof +D /path
   9 
  10 # Files by user
  11 lsof -u name
  12 lsof -u name1,name2
  13 lsof -u name1 -u name2
  14 
  15 # By program name
  16 lsof -c apache
  17 
  18 # AND'ing selection conditions
  19 lsof -u www-data -c apache
  20 
  21 # By pid
  22 lsof -p 1
  23 
  24 # Except certain pids
  25 lsof -p ^1
  26 
  27 # TCP and UDP connections
  28 lsof -i
  29 lsof -i tcp # TCP connections
  30 lsof -i udp # UDP connections
  31 
  32 # By port
  33 lsof -i :25
  34 lsof -i :smtp
  35 lsof -i udp:53
  36 lsof -i tcp:80
  37 
  38 # All network activity by a user
  39 lsof -a -u name1 -i
  40 
  41 lsof -N # NFS use
  42 lsof -U # UNIX domain socket use
  43 
  44 # List PIDs
  45 lsof -t -i
  46 kill -9 $(lsof -t -i) # Kill all programs w/network activity
  47 


CategoryCheatSheet

SamatsWiki: CheatSheet/lsof (last edited 2010-11-25 08:55:24 by SamatJain)