The error -bash: lsof: command not found indicates that the lsof command is not installed on your system. To use lsof, you need to install it first.
Steps to Install lsof
- For RHEL/CentOS-based systems (including Amazon Linux):
Run the following command to install lsof:
sudo yum install -y lsof
- For Debian/Ubuntu-based systems:
Run:
sudo apt update
sudo apt install -y lsof
- Verify the Installation:
After installation, verify that lsof is available:
lsof -v
- Re-run the Command:
After lsof is installed, you can run:
lsof -iTCP | grep LISTEN
If you are unable to install software due to restrictions or package manager issues, you can use netstat (if available) as an alternative:
netstat -antp | grep LISTEN