Skip to content

Instantly share code, notes, and snippets.

@sergepetit
Last active May 12, 2022 12:39
Show Gist options
  • Save sergepetit/6987439 to your computer and use it in GitHub Desktop.
Save sergepetit/6987439 to your computer and use it in GitHub Desktop.
Shell command lsof : see open files and ports; Selection is OR by default, use -a for AND; Tested on OSX
#List all ports for tcp
sudo lsof -itcp
#all ports for tcp, dont resolve port name from numbers
sudo lsof -itcp -P
#open files and ports of process #$PID
sudo lsof -p $PID
#only ports of tcp for process #$PID, dont resolve port name, dont resolve ip name
sudo lsof -a -p $PID -P -n -itcp
#only ports of tcp for process #$PID, dont resolve port name, dont resolve ip name, refresh every 5 seconds
sudo lsof -a -p $PID -P -n -itcp -r 5
#search by file (can be slow)
sudo lsof /complete/path/to/file
#plenty more options and usage patterns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment