Created
May 7, 2025 14:25
-
-
Save petergi/bd5d18a7204c58fde9f59cb83e57dbcf to your computer and use it in GitHub Desktop.
You know.. a couple of handy examples of how to use lsof...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Find what's using a volume on macOS | |
lsof | grep /Volumes/ | |
# Check what processes are listening on port | |
lsof -iTCP -sTCP:LISTEN -P -n | |
# Kills a process using PID | |
# | |
# awk grabs the PIDs. | |
# tail gets rid of the pesky first entry: "PID". | |
# xargs executes kill -9 on the PIDs. | |
# The -r / --no-run-if-empty, prevents kill command failure, in case lsof did not return any PID. | |
lsof +D ./ | awk '{print $2}' | tail -n +2 | xargs -r kill -9 | |
# Kills the process running on a port | |
lsof -t -t:port | xargs kill | |
# Determines which app is opening too many files | |
lsof -n | awk '{print $1}' | uniq -c | sort -rn | head -n $LINES |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment