lsof

Table of Contents

1. Common options

  • Operations
    • -a : Used as AND
  • Network
    • -P : Use port numbers instead of port names
    • -n : Don't convert network addresses to hostnames
    • -s : Specify state for network files
    • -i : Network patterns

2. Search by

  • File by path

    lsof | rg '/geekodour' # get all files which has the path
    
  • File by user

    lsof -u rms,root
    lsof -u ^root # except user
    
  • File by program name

    lsof -c apache
    
  • File by PID

    lsof -p 450,980,333
    lsof -p 450,980,333 +fg # show show file flags
    lsof <ANY_COMMAND> -t # just gives you the PIDs, so that you can use it on another command
    
  • File by FD

    lsof -d <fd_number/range>
    
  • File by network

    lsof -i [optional(tcp/udp)] -P
    lsof -i :25 # find by port no
    lsof -U # unix domain sockets
    lsof -a -u geekdour -i # network activity by user
    lsof -nP -iTCP -sTCP:LISTEN
    

3. Resources

Created: 2024-07-16 Tue 16:44

Validate