Table of Contents
#Introduction
lsof command meaning “List open files“. This command will not find CentOS7/RHEL. We will install lsof command example as below:
$ sudo yum install lsof
Basic Usage
lsof
This will display a list of all open files and the processes that are using them.
lsof command example

List open files
$ lsof -n
Kill a process running on port 8443
$ lsof -i :8443 | awk '{print $2}' | tail -n 1 | xargs kill
# or
$ lsof -i :8443 | awk 'NR > 1 {print $2}' | xargs --no-run-if-empty kill
Show the 15 Largest Open Files.
$ lsof / | awk '{ if($7 > 1048576) print $7/1048576 "MB" " " $9 " " $1 }' | sort -n -u | tail -n 15
List User-Specific Opened Files. This will display a list of all open files that are being used by the specified user.
$ lsof -u huupv
Search by PID
$ lsof -p 1
Exclude User with ^ Character
$ lsof -i -u^root
List TCP Port ranges 8000-9000
$ lsof -i TCP:8000-9000
Conclusion
lsof is a simple command in Linux. I hope will this your helpful. Thank you for reading the DevopsRoles page!