SlideShare a Scribd company logo
1 of 10
Download to read offline
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

What's hot

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

What's hot (20)

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

Similar to LSOF Command Usage on RHEL 7

Similar to LSOF Command Usage on RHEL 7 (20)

Linux And perl
Linux And perlLinux And perl
Linux And perl
 
Linux Presentation
Linux PresentationLinux Presentation
Linux Presentation
 
Unix Administration 2
Unix Administration 2Unix Administration 2
Unix Administration 2
 
Linux Internals - Part I
Linux Internals - Part ILinux Internals - Part I
Linux Internals - Part I
 
Learning Linux Series Administrator Commands.pptx
Learning Linux Series Administrator Commands.pptxLearning Linux Series Administrator Commands.pptx
Learning Linux Series Administrator Commands.pptx
 
Power point on linux commands,appache,php,mysql,html,css,web 2.0
Power point on linux commands,appache,php,mysql,html,css,web 2.0Power point on linux commands,appache,php,mysql,html,css,web 2.0
Power point on linux commands,appache,php,mysql,html,css,web 2.0
 
Linux presentation
Linux presentationLinux presentation
Linux presentation
 
Linux week 2
Linux week 2Linux week 2
Linux week 2
 
8.1.intro unix
8.1.intro unix8.1.intro unix
8.1.intro unix
 
Linux ppt
Linux pptLinux ppt
Linux ppt
 
Linux
LinuxLinux
Linux
 
Linux
Linux Linux
Linux
 
Linux
LinuxLinux
Linux
 
Linux Commands
Linux CommandsLinux Commands
Linux Commands
 
Most frequently used unix commands for database administrator
Most frequently used unix commands for database administratorMost frequently used unix commands for database administrator
Most frequently used unix commands for database administrator
 
Linux Server Deep Dives (DrupalCon Amsterdam)
Linux Server Deep Dives (DrupalCon Amsterdam)Linux Server Deep Dives (DrupalCon Amsterdam)
Linux Server Deep Dives (DrupalCon Amsterdam)
 
Intro to linux systems administration
Intro to linux systems administrationIntro to linux systems administration
Intro to linux systems administration
 
linux cmds.pptx
linux cmds.pptxlinux cmds.pptx
linux cmds.pptx
 
Directories description
Directories descriptionDirectories description
Directories description
 
17 Linux Basics #burningkeyboards
17 Linux Basics #burningkeyboards17 Linux Basics #burningkeyboards
17 Linux Basics #burningkeyboards
 

More from VCP Muthukrishna

How to Fix Duplicate Packages in YUM on CentOS 7
How to Fix Duplicate Packages in YUM on CentOS 7How to Fix Duplicate Packages in YUM on CentOS 7
How to Fix Duplicate Packages in YUM on CentOS 7VCP Muthukrishna
 
How To Install and Configure GNome on CentOS 7
How To Install and Configure GNome on CentOS 7How To Install and Configure GNome on CentOS 7
How To Install and Configure GNome on CentOS 7VCP Muthukrishna
 
How To Connect to Active Directory User Validation
How To Connect to Active Directory User ValidationHow To Connect to Active Directory User Validation
How To Connect to Active Directory User ValidationVCP Muthukrishna
 
How To Connect To Active Directory PowerShell
How To Connect To Active Directory PowerShellHow To Connect To Active Directory PowerShell
How To Connect To Active Directory PowerShellVCP Muthukrishna
 
How To List Files on Remote Server - PowerShell
How To List Files on Remote Server - PowerShellHow To List Files on Remote Server - PowerShell
How To List Files on Remote Server - PowerShellVCP Muthukrishna
 
How To List Files and Display In HTML Format
How To List Files and Display In HTML FormatHow To List Files and Display In HTML Format
How To List Files and Display In HTML FormatVCP Muthukrishna
 
How To Check and Delete a File via PowerShell
How To Check and Delete a File via PowerShellHow To Check and Delete a File via PowerShell
How To Check and Delete a File via PowerShellVCP Muthukrishna
 
Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...
Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...
Zimbra Troubleshooting - Mails not being Delivered or Deferred or Connection ...VCP Muthukrishna
 
How To Setup SSH Keys on CentOS 7
How To Setup SSH Keys on CentOS 7How To Setup SSH Keys on CentOS 7
How To Setup SSH Keys on CentOS 7VCP Muthukrishna
 
Windows PowerShell Basics - How To List PSDrive Info
Windows PowerShell Basics - How To List PSDrive InfoWindows PowerShell Basics - How To List PSDrive Info
Windows PowerShell Basics - How To List PSDrive InfoVCP Muthukrishna
 
How To List Nginx Modules Installed / Complied on CentOS 7
How To List Nginx Modules Installed / Complied on CentOS 7How To List Nginx Modules Installed / Complied on CentOS 7
How To List Nginx Modules Installed / Complied on CentOS 7VCP Muthukrishna
 
Windows PowerShell Basics – How To Create powershell for loop
Windows PowerShell Basics – How To Create powershell for loopWindows PowerShell Basics – How To Create powershell for loop
Windows PowerShell Basics – How To Create powershell for loopVCP Muthukrishna
 
How To Construct IF and Else Conditional Statements
How To Construct IF and Else Conditional StatementsHow To Construct IF and Else Conditional Statements
How To Construct IF and Else Conditional StatementsVCP Muthukrishna
 
How To Create PowerShell Function Mandatory Parameter and Optional Parameter
How To Create PowerShell Function Mandatory Parameter and Optional ParameterHow To Create PowerShell Function Mandatory Parameter and Optional Parameter
How To Create PowerShell Function Mandatory Parameter and Optional ParameterVCP Muthukrishna
 
How To Create Power Shell Function Mandatory Parameter Value
How To Create Power Shell Function Mandatory Parameter ValueHow To Create Power Shell Function Mandatory Parameter Value
How To Create Power Shell Function Mandatory Parameter ValueVCP Muthukrishna
 
How To Create PowerShell Function
How To Create PowerShell FunctionHow To Create PowerShell Function
How To Create PowerShell FunctionVCP Muthukrishna
 
How To Disable IE Enhanced Security Windows PowerShell
How To Disable IE Enhanced Security Windows PowerShellHow To Disable IE Enhanced Security Windows PowerShell
How To Disable IE Enhanced Security Windows PowerShellVCP Muthukrishna
 
How To Check IE Enhanced Security Is Enabled Windows PowerShell
How To Check IE Enhanced Security Is Enabled Windows PowerShellHow To Check IE Enhanced Security Is Enabled Windows PowerShell
How To Check IE Enhanced Security Is Enabled Windows PowerShellVCP Muthukrishna
 
Nginx bind() to 0.0.0.0:9080 failed
Nginx bind() to 0.0.0.0:9080 failedNginx bind() to 0.0.0.0:9080 failed
Nginx bind() to 0.0.0.0:9080 failedVCP Muthukrishna
 
How To Install and Configure Screen on CentOS 7
How To Install and Configure Screen on CentOS 7How To Install and Configure Screen on CentOS 7
How To Install and Configure Screen on CentOS 7VCP Muthukrishna
 

More from VCP Muthukrishna (20)

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

Recently uploaded

Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 

Recently uploaded (20)

Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 

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`