SlideShare a Scribd company logo
LSOF Usage Guide on RHEL 7
i | P a g e
Table of Contents
Overview.......................................................................................................................................................1
Applies To......................................................................................................................................................1
Pre-Requisites ...............................................................................................................................................1
Install Package...............................................................................................................................................1
Validate Package Installation........................................................................................................................1
File Descriptor Table .................................................................................................................................2
Type Descriptor Table...............................................................................................................................2
List of Opened Files – User............................................................................................................................3
List of Opened Files – Exclude User ..............................................................................................................3
List of Opened Files – Directory....................................................................................................................4
List of Open Files – By Process Name Starting With.....................................................................................4
List of Open Files – By PID.............................................................................................................................5
List Processes – By Specific File.....................................................................................................................5
List all Network Connections ........................................................................................................................6
List Network Connections – Only IPv4..........................................................................................................6
List Network Connections – Only IPv6..........................................................................................................6
List Network Connections – TCP Port Range ................................................................................................7
List Network Connections – UDP Port Range ...............................................................................................7
Find Processes Running – Specific Port.........................................................................................................7
List all network files in use by a specific process..........................................................................................7
List of Files in Repeat Mode..........................................................................................................................8
List of Files in Repeat Mode..........................................................................................................................8
List all NFS files..............................................................................................................................................9
Kill All process of a particular user................................................................................................................9
LSOF Usage Guide on RHEL 7
1 | P a g e
Overview
The purpose of this document is guide you the usage of “lsof” command. LSOF command is utilized to
know the “LiSt of Open Files” by processes. As we are aware Linux / Unix considers everything as files such
as (pipes, sockets, devices, etc.).
This command is also useful when you want to unmount filesystem and but you are unable to unmount
filesystem or process is running is memory. It is also useful wherein a file is deleted and file is resident in
memory. lsof command will help us to find out files that are currently in use and its current state of such
files.
Applies To
Tested on RHEL 7, CentOS 7.
Pre-Requisites
 lsof package is installed
Install Package
LSOF package is installed by default in when you install operating system, in order to install the package
if the package is not installed run the command;
yum install -y lsof
Validate Package Installation
To verify the package installation status, run the command;
rpm -qa | grep lsof
LSOF Usage Guide on RHEL 7
2 | P a g e
First you need to understand the output of lsof command, below will give you a brief insight to different
sections.
FD and Types are the that we will focus upon, reset of the fields are self-explanatory.
File Descriptor Table
FD stands for File Descriptor and it has different values are listed when you the command. A few of them
are listed below.
File Descriptor Purpose
cwd current working directory
rtd root directory
pd parent directory
txt program text (code and data)
mem memory-mapped file
mmap Memory mapped device
number character The character after the number i.e ‘1u’, represents the
mode in which the file is opened.
r for read, w for write, u for read and write.
Type Descriptor Table
Specifies the type of the file. Some of the values of TYPEs are,
Type Descriptor Type of File
REG Regular File
DIR Directory
FIFO First In First Out
CHR Character special file
LSOF Usage Guide on RHEL 7
3 | P a g e
List of Opened Files – User
To list the files opened by a user, run the command;
lsof -u chrony
Note: To list of files that are open for multiple users run the command lsof -u mysql -u postfix.
List of Opened Files – Exclude User
To list of open files excluding a user(s), execute with option “-u” and “^” along with the user, run the
command;
lsof -u^root
Note: To exclude results of additional users, run the command lsof -u ^mysql -u ^chrony -u ^dbus.
LSOF Usage Guide on RHEL 7
4 | P a g e
List of Opened Files – Directory
To list the files that are opened in a specific directory, run the command;
lsof +D /var/log/
List of Open Files – By Process Name Starting With
List the files that are open by process name(s) starting with, run the command;
lsof -c mysql
Note: To list of files that are open for multiple process names run the command lsof -c mysql -c systemd.
LSOF Usage Guide on RHEL 7
5 | P a g e
List of Open Files – By PID
To list files that are open by process id, run the command;
ps -ef | grep [m]ysqld_safe
lsof -p 1164
List Processes – By Specific File
To list the processes associated with a specific file, run the command;
lsof /var/log/Xorg.0.log
LSOF Usage Guide on RHEL 7
6 | P a g e
List all Network Connections
List all the network connections listening and established, run the command;
lsof -i
List Network Connections – Only IPv4
List all IPv4 network connections listening and established, run the command;
lsof -i 4
List Network Connections – Only IPv6
List all IPv6 network connections listening and established, run the command;
lsof -i 6
LSOF Usage Guide on RHEL 7
7 | P a g e
List Network Connections – TCP Port Range
List all the network connections listening and established for TCP port range, Run the command;
lsof -i TCP:1-1024
List Network Connections – UDP Port Range
List all the network connections listening and established for UDP port range, run the command;
lsof -i UDP:1-1024
Find Processes Running – Specific Port
To list the process running on a specific port, run the command;
lsof -i :22
List all network files in use by a specific process
To list all the network files which is being used by a process; run the command
lsof -i -a -p 8132 or lsof -i -a -c ssh
LSOF Usage Guide on RHEL 7
8 | P a g e
List of Files in Repeat Mode
To list the files that are opened in repeat mode (loop until no files are open) “+” is prefixed before
command “repeat option r” and refresh the output every 2 seconds, run the command;
lsof -i -a -c ssh +r2
Note: Each cycle output is separated by “=======”
List of Files in Repeat Mode
To list the files that are opened in repeat mode (loop until interrupt “ctrl +c”) “-” is prefixed before
command “repeat option r” and refresh the output every 5 seconds, run the command;
lsof -i -a -c ssh -r5
Note: Each cycle output is separated by “=======”
LSOF Usage Guide on RHEL 7
9 | P a g e
List all NFS files
To list Network file system files in use, for a user. Run the command;
lsof -N -u root -a
Note: In this case there is NFS is not utilized.
Kill All Process of a Particular User
To list and kill all the process of a particular user; “-t” option will list only the process id of the user, run
the command;
lsof -t -u postfix
kill -9 `lsof -t -u postfix`

More Related Content

PDF
SystemD Usage Guide
PDF
Linux Basic Administration Commands Guide
PDF
How To View Login History and Logout History on RHEL 7
PDF
How To Protect SSH Access with Fail2Ban on RHEL 7
PDF
How to Configure OpenFiler for NFS Share
PDF
How To Install and Configure Splunk on RHEL 7 in AWS
PDF
How To Configure Apache VirtualHost on RHEL 7 on AWS
PDF
How To Install and Configure SUDO on RHEL 7
SystemD Usage Guide
Linux Basic Administration Commands Guide
How To View Login History and Logout History on RHEL 7
How To Protect SSH Access with Fail2Ban on RHEL 7
How to Configure OpenFiler for NFS Share
How To Install and Configure Splunk on RHEL 7 in AWS
How To Configure Apache VirtualHost on RHEL 7 on AWS
How To Install and Configure SUDO on RHEL 7

What's hot (20)

PDF
How to installation and configure apache2
PDF
How To Install and Configure Log Rotation on RHEL 7 or CentOS 7
PDF
How To Install OpenFire in CentOS 7
PDF
How To Install and Generate Audit Reports in CentOS 7 or RHEL 7
PDF
How To Install CentOS 7
PDF
How To Configure Nginx Load Balancer on CentOS 7
PDF
Configure Run Levels RHEL 7 or CentOS 7
PDF
How To Install and Configure VSFTPD on RHEL 7 or CentOS 7
PDF
How To Install and Configure Apache SSL on CentOS 7
PDF
How To Install and Use ABRT CLI on RHEL 7
PDF
How To Configure SNMP Logging on RHEL 7
PDF
Installation CentOS 6.3
PDF
How To Install and Configure Chrony on RHEL 7
PDF
How To Configure FirewallD on RHEL 7 or CentOS 7
PDF
How to Install Configure and Use sysstat utils on RHEL 7
PDF
Install and Configure RSyslog – CentOS 7 / RHEL 7
PDF
How to Manage journalctl Logging System on RHEL 7
PDF
How To Install and Configure AWS CLI on RHEL 7
PDF
How To Install and Configure Open SSH Server on Ubuntu
PDF
How To Configure Amazon EC2 Load Balancer
How to installation and configure apache2
How To Install and Configure Log Rotation on RHEL 7 or CentOS 7
How To Install OpenFire in CentOS 7
How To Install and Generate Audit Reports in CentOS 7 or RHEL 7
How To Install CentOS 7
How To Configure Nginx Load Balancer on CentOS 7
Configure Run Levels RHEL 7 or CentOS 7
How To Install and Configure VSFTPD on RHEL 7 or CentOS 7
How To Install and Configure Apache SSL on CentOS 7
How To Install and Use ABRT CLI on RHEL 7
How To Configure SNMP Logging on RHEL 7
Installation CentOS 6.3
How To Install and Configure Chrony on RHEL 7
How To Configure FirewallD on RHEL 7 or CentOS 7
How to Install Configure and Use sysstat utils on RHEL 7
Install and Configure RSyslog – CentOS 7 / RHEL 7
How to Manage journalctl Logging System on RHEL 7
How To Install and Configure AWS CLI on RHEL 7
How To Install and Configure Open SSH Server on Ubuntu
How To Configure Amazon EC2 Load Balancer
Ad

Similar to LSOF Command Usage on RHEL 7 (20)

PPTX
Linux And perl
PPTX
Linux Presentation
PPT
Unix Administration 2
PDF
PPTX
Learning Linux Series Administrator Commands.pptx
PPT
Power point on linux commands,appache,php,mysql,html,css,web 2.0
PPT
Linux presentation
PPTX
Linux week 2
PPT
8.1.intro unix
PPT
Linux ppt
PPTX
PPTX
OS-Module 2 Linux Programming Important topics
PPT
PPTX
PPT
Linux Commands
DOC
Most frequently used unix commands for database administrator
PDF
Linux Server Deep Dives (DrupalCon Amsterdam)
PPT
Intro to linux systems administration
PPTX
linux cmds.pptx
DOCX
Directories description
Linux And perl
Linux Presentation
Unix Administration 2
Learning Linux Series Administrator Commands.pptx
Power point on linux commands,appache,php,mysql,html,css,web 2.0
Linux presentation
Linux week 2
8.1.intro unix
Linux ppt
OS-Module 2 Linux Programming Important topics
Linux Commands
Most frequently used unix commands for database administrator
Linux Server Deep Dives (DrupalCon Amsterdam)
Intro to linux systems administration
linux cmds.pptx
Directories description
Ad

More from VCP Muthukrishna (20)

PDF
How to Fix Duplicate Packages in YUM on CentOS 7
PDF
How To Install and Configure GNome on CentOS 7
PDF
How To Connect to Active Directory User Validation
PDF
How To Connect To Active Directory PowerShell
PDF
How To List Files on Remote Server - PowerShell
PDF
How To List Files and Display In HTML Format
PDF
How To Check and Delete a File via PowerShell
PDF
Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...
PDF
How To Setup SSH Keys on CentOS 7
PDF
Windows PowerShell Basics - How To List PSDrive Info
PDF
How To List Nginx Modules Installed / Complied on CentOS 7
PDF
Windows PowerShell Basics – How To Create powershell for loop
PDF
How To Construct IF and Else Conditional Statements
PDF
How To Create PowerShell Function Mandatory Parameter and Optional Parameter
PDF
How To Create Power Shell Function Mandatory Parameter Value
PDF
How To Create PowerShell Function
PDF
How To Disable IE Enhanced Security Windows PowerShell
PDF
How To Check IE Enhanced Security Is Enabled Windows PowerShell
PDF
Nginx bind() to 0.0.0.0:9080 failed
PDF
How To Install and Configure Screen on CentOS 7
How to Fix Duplicate Packages in YUM on CentOS 7
How To Install and Configure GNome on CentOS 7
How To Connect to Active Directory User Validation
How To Connect To Active Directory PowerShell
How To List Files on Remote Server - PowerShell
How To List Files and Display In HTML Format
How To Check and Delete a File via PowerShell
Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...
How To Setup SSH Keys on CentOS 7
Windows PowerShell Basics - How To List PSDrive Info
How To List Nginx Modules Installed / Complied on CentOS 7
Windows PowerShell Basics – How To Create powershell for loop
How To Construct IF and Else Conditional Statements
How To Create PowerShell Function Mandatory Parameter and Optional Parameter
How To Create Power Shell Function Mandatory Parameter Value
How To Create PowerShell Function
How To Disable IE Enhanced Security Windows PowerShell
How To Check IE Enhanced Security Is Enabled Windows PowerShell
Nginx bind() to 0.0.0.0:9080 failed
How To Install and Configure Screen on CentOS 7

Recently uploaded (20)

PDF
Machine learning based COVID-19 study performance prediction
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Approach and Philosophy of On baking technology
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PDF
August Patch Tuesday
PPTX
Machine Learning_overview_presentation.pptx
PPTX
A Presentation on Artificial Intelligence
PDF
Encapsulation theory and applications.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
TLE Review Electricity (Electricity).pptx
PDF
NewMind AI Weekly Chronicles - August'25-Week II
Machine learning based COVID-19 study performance prediction
Univ-Connecticut-ChatGPT-Presentaion.pdf
Assigned Numbers - 2025 - Bluetooth® Document
Accuracy of neural networks in brain wave diagnosis of schizophrenia
MIND Revenue Release Quarter 2 2025 Press Release
Network Security Unit 5.pdf for BCA BBA.
Approach and Philosophy of On baking technology
Mobile App Security Testing_ A Comprehensive Guide.pdf
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Heart disease approach using modified random forest and particle swarm optimi...
August Patch Tuesday
Machine Learning_overview_presentation.pptx
A Presentation on Artificial Intelligence
Encapsulation theory and applications.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
TLE Review Electricity (Electricity).pptx
NewMind AI Weekly Chronicles - August'25-Week II

LSOF Command Usage on RHEL 7

  • 1. LSOF Usage Guide on RHEL 7 i | P a g e Table of Contents Overview.......................................................................................................................................................1 Applies To......................................................................................................................................................1 Pre-Requisites ...............................................................................................................................................1 Install Package...............................................................................................................................................1 Validate Package Installation........................................................................................................................1 File Descriptor Table .................................................................................................................................2 Type Descriptor Table...............................................................................................................................2 List of Opened Files – User............................................................................................................................3 List of Opened Files – Exclude User ..............................................................................................................3 List of Opened Files – Directory....................................................................................................................4 List of Open Files – By Process Name Starting With.....................................................................................4 List of Open Files – By PID.............................................................................................................................5 List Processes – By Specific File.....................................................................................................................5 List all Network Connections ........................................................................................................................6 List Network Connections – Only IPv4..........................................................................................................6 List Network Connections – Only IPv6..........................................................................................................6 List Network Connections – TCP Port Range ................................................................................................7 List Network Connections – UDP Port Range ...............................................................................................7 Find Processes Running – Specific Port.........................................................................................................7 List all network files in use by a specific process..........................................................................................7 List of Files in Repeat Mode..........................................................................................................................8 List of Files in Repeat Mode..........................................................................................................................8 List all NFS files..............................................................................................................................................9 Kill All process of a particular user................................................................................................................9
  • 2. LSOF Usage Guide on RHEL 7 1 | P a g e Overview The purpose of this document is guide you the usage of “lsof” command. LSOF command is utilized to know the “LiSt of Open Files” by processes. As we are aware Linux / Unix considers everything as files such as (pipes, sockets, devices, etc.). This command is also useful when you want to unmount filesystem and but you are unable to unmount filesystem or process is running is memory. It is also useful wherein a file is deleted and file is resident in memory. lsof command will help us to find out files that are currently in use and its current state of such files. Applies To Tested on RHEL 7, CentOS 7. Pre-Requisites  lsof package is installed Install Package LSOF package is installed by default in when you install operating system, in order to install the package if the package is not installed run the command; yum install -y lsof Validate Package Installation To verify the package installation status, run the command; rpm -qa | grep lsof
  • 3. LSOF Usage Guide on RHEL 7 2 | P a g e First you need to understand the output of lsof command, below will give you a brief insight to different sections. FD and Types are the that we will focus upon, reset of the fields are self-explanatory. File Descriptor Table FD stands for File Descriptor and it has different values are listed when you the command. A few of them are listed below. File Descriptor Purpose cwd current working directory rtd root directory pd parent directory txt program text (code and data) mem memory-mapped file mmap Memory mapped device number character The character after the number i.e ‘1u’, represents the mode in which the file is opened. r for read, w for write, u for read and write. Type Descriptor Table Specifies the type of the file. Some of the values of TYPEs are, Type Descriptor Type of File REG Regular File DIR Directory FIFO First In First Out CHR Character special file
  • 4. LSOF Usage Guide on RHEL 7 3 | P a g e List of Opened Files – User To list the files opened by a user, run the command; lsof -u chrony Note: To list of files that are open for multiple users run the command lsof -u mysql -u postfix. List of Opened Files – Exclude User To list of open files excluding a user(s), execute with option “-u” and “^” along with the user, run the command; lsof -u^root Note: To exclude results of additional users, run the command lsof -u ^mysql -u ^chrony -u ^dbus.
  • 5. LSOF Usage Guide on RHEL 7 4 | P a g e List of Opened Files – Directory To list the files that are opened in a specific directory, run the command; lsof +D /var/log/ List of Open Files – By Process Name Starting With List the files that are open by process name(s) starting with, run the command; lsof -c mysql Note: To list of files that are open for multiple process names run the command lsof -c mysql -c systemd.
  • 6. LSOF Usage Guide on RHEL 7 5 | P a g e List of Open Files – By PID To list files that are open by process id, run the command; ps -ef | grep [m]ysqld_safe lsof -p 1164 List Processes – By Specific File To list the processes associated with a specific file, run the command; lsof /var/log/Xorg.0.log
  • 7. LSOF Usage Guide on RHEL 7 6 | P a g e List all Network Connections List all the network connections listening and established, run the command; lsof -i List Network Connections – Only IPv4 List all IPv4 network connections listening and established, run the command; lsof -i 4 List Network Connections – Only IPv6 List all IPv6 network connections listening and established, run the command; lsof -i 6
  • 8. LSOF Usage Guide on RHEL 7 7 | P a g e List Network Connections – TCP Port Range List all the network connections listening and established for TCP port range, Run the command; lsof -i TCP:1-1024 List Network Connections – UDP Port Range List all the network connections listening and established for UDP port range, run the command; lsof -i UDP:1-1024 Find Processes Running – Specific Port To list the process running on a specific port, run the command; lsof -i :22 List all network files in use by a specific process To list all the network files which is being used by a process; run the command lsof -i -a -p 8132 or lsof -i -a -c ssh
  • 9. LSOF Usage Guide on RHEL 7 8 | P a g e List of Files in Repeat Mode To list the files that are opened in repeat mode (loop until no files are open) “+” is prefixed before command “repeat option r” and refresh the output every 2 seconds, run the command; lsof -i -a -c ssh +r2 Note: Each cycle output is separated by “=======” List of Files in Repeat Mode To list the files that are opened in repeat mode (loop until interrupt “ctrl +c”) “-” is prefixed before command “repeat option r” and refresh the output every 5 seconds, run the command; lsof -i -a -c ssh -r5 Note: Each cycle output is separated by “=======”
  • 10. LSOF Usage Guide on RHEL 7 9 | P a g e List all NFS files To list Network file system files in use, for a user. Run the command; lsof -N -u root -a Note: In this case there is NFS is not utilized. Kill All Process of a Particular User To list and kill all the process of a particular user; “-t” option will list only the process id of the user, run the command; lsof -t -u postfix kill -9 `lsof -t -u postfix`