-
View the top 10 processes with the most open files on your system.
lsof -n | awk '{print $1}' | sort | uniq -c | sort -nr | head -10
-
List all open TCP and UDP ports and their associated processes
lsof -i | grep -E "(LISTEN|UDP)" | awk '{print $1, $9}' | sort | uniq
-
List all listening ports and their associated process names
lsof -i -P -n | grep LISTEN | awk '{print $9, $1}' | sort | uniq
-
Find all open files larger than a specific size, such as 100MB, and sort by size
lsof -s | awk '$7 > 100*1024*1024 {print $7, $1, $2, $9}' | sort -nr
-
Count the number of open files per process, sorted by process name
lsof -n | cut -f1 -d' ' | sort | uniq -c | sort -k2,2
Useful lsof commands
Posted on:May 9, 2023 at 05:49 AM