lsof command example

#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

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!

,

About HuuPV

My name is Huu. I love technology and especially Devops Skill such as Docker, vagrant, git so forth. I likes open-sources. so I created DevopsRoles.com site to share the knowledge that I have learned. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.