lsof command not found on CentOS 7 / RHEL 7 Server

lsof command not found

 

I got the error ‘lsof command not found’ on my CentOS 7 server. lsof means ‘List Open Files’. Lsof is used to find all files that are open by a process that is running on the server.

root@centos7 [/]# lsof -i :443
-bash: /usr/sbin/lsof: No such file or directory

[root@centos7 ~]# lsof -p 443
-bash: lsof: command not found

Error shows that lsof command is not installed on your server. Do the below steps to install lsof command on your CentOS 7 / Redhat 7 Server.

1. Log into your linux server via SSH as root

2. Install lsof package on the server using yum

3. Enter ‘y’ if yum ask for confirmation while installing lsof
 

[root@centos7 /]# yum install lsof

Resolving Dependencies
–> Running transaction check
—> Package lsof.x86_64 0:4.87-6.el7 will be installed
–> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================================================================================
Package Arch Version Repository Size
==================================================================================================================================================================
Installing:
lsof x86_64 4.87-6.el7 base 331 k

Transaction Summary
==================================================================================================================================================================
Install 1 Package

Total download size: 331 k
Installed size: 927 k
Is this ok [y/d/N]: y
Downloading packages:
lsof-4.87-6.el7.x86_64.rpm | 331 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : lsof-4.87-6.el7.x86_64 1/1
Verifying : lsof-4.87-6.el7.x86_64 1/1

Installed:
lsof.x86_64 0:4.87-6.el7

Complete!

 
Now lsof package is installed on your Linux Server.
 

lsof command not found - How to install lsof command

lsof command not found – How to install lsof command


 
 

How to download and install lsof rpm on CentOS 7 / RHEL 7 server


 
1. Log into your CentOS 7 / RHEL 7 server as root user

2. Download lsof rpm from CentOS website using wget command
 

[root@redhat /]# wget http://mirror.centos.org/centos/7/os/x86_64/Packages/lsof-4.87-6.el7.x86_64.rpm

Saving to: ‘lsof-4.87-6.el7.x86_64.rpm’

100%[===============================>] 338,864 1.37MB/s in 0.2s

2020-11-17 17:55:42 (1.37 MB/s) – ‘lsof-4.87-6.el7.x86_64.rpm’ saved [338864/338864]

 

3. Install the downloaded rpm file either using yum or rpm command

 

# yum install lsof-4.87-6.el7.x86_64.rpm

 
yum command will lsof package and the required dependencies

 

[root@redhat /]# rpm -Uvh lsof-4.87-6.el7.x86_64.rpm

Preparing… ################################# [100%]
Updating / installing…
1:lsof-4.87-6.el7 ################################# [100%]

 
You must first install the dependencies, if you are installing lsof package using rpm command.

lsof command need the below dependencies :

glibc
libselinux

The above dependencies will be installed by default on CentOS7 / RHEL7 server.