10 Representative Of Lsof Commands Inwards Unix As Well As Linux
It's been a long fourth dimension since I conduct keep written anything on UNIX or Linux commands, but today I'll verbalise most the lsof command, a utility ascendency every organization admin together with developers love. The lsof ascendency stands for listing opened upwards file descriptors together with equally the advert suggests, it is used to notice opened upwards files yesteryear process. Since almost everything inwards UNIX are file, you lot tin hand the axe role lsof ascendency to notice an opened upwards regular file, a directory, a symbolic link, a block special file, an NFS mounted file, a socket stream, a shared library, a grapheme special file, a regular pipe, a named pipe, an mesh socket, a UNIX domain socket, together with many others. I conduct keep mostly used it to notice all the files opened yesteryear a detail process, which I volition demo you lot inwards the coming section.
It's an incredibly useful tool to create debugging together with troubleshooting inwards UNIX together with Linux environment, together with because of its versatile nature, it's also known equally the "The Swiss Army Knife of Linux". Since most of the production organization runs on the UNIX-based operating system, noesis of this tool croak fifty-fifty to a greater extent than important.
As a Java developer, I oftentimes role lsof command to notice all the files opened my Java process, or about fourth dimension to notice which procedure has opened a detail file e.g. a file which is used to correspond a cache inwards memory, lsof is incredibly useful on doing that.
In this tutorial, nosotros are going to larn dissimilar ways together with options to role lsof about task, which volition farther assist you lot to notice procedure together with file related information inwards UNIX or Linux. You tin hand the axe combine the lsof amongst grep command for advanced search together with filtering.
I oftentimes role grep ascendency to filter output based upon file name, procedure id or file type. If you lot are non familiar amongst basic commands similar grep together with find, together with then I advise you lot conduct keep a await at Linux Command Line Basics on Udemy, a basic class for whatever programmer, tester, information safety people or anyone, who operate on UNIX together with Linux based environment.
1) How to listing all opened upwards files yesteryear all process
Simply running lsof without whatever declaration impress all opened file together with process. This is non especially useful but a skillful starting point.
2) How to listing all procedure which has opened a file
volition listing all the procedure which has opened this file. you lot tin hand the axe run into the command, PID, user, together with total file path to find out the process.
3) How to notice all opened files yesteryear a user
You tin hand the axe role lsof -u ascendency to listing all opened file yesteryear a user equally shown below
You tin hand the axe render comma separated listing of users to notice a list of opened upwards files yesteryear multiple users equally shown below
You tin hand the axe create the same yesteryear providing -u pick multiple times :
If you lot are struggling to recall these lsof ascendency options, hither is a dainty diagram from Julia Evans which volition assist them to remember. If you lot want, you lot tin hand the axe also bring together the Learn The Linux Command Line: Basic Commands, a gratuitous class on Udemy for learning essential Linux commands for FREE.
4) How to listing all files opened yesteryear a detail command
You tin hand the axe role lsof -c pick to render the advert of the ascendency together with listing downwards all the files opened yesteryear that command, for example, to listing all file opened yesteryear java process, you lot tin hand the axe create this :
This is meliorate than using grep for filtering, equally instead of writing lsof | grep java, you lot tin hand the axe simply write lsof -c java.
You tin hand the axe also notice all files opened yesteryear apache which runs as httpd equally shown below :
Just similar multiple users, you lot tin hand the axe also combine multiple processes advert to listing downwards files concur yesteryear them e.g.
5) How to notice all files opened yesteryear a detail user together with command
You tin hand the axe combine users together with procedure advert inwards i lsof ascendency to listing downwards all the files opened yesteryear a detail procedure or a detail user equally shown below :
This volition listing all files opened or concur yesteryear root user + all files opened yesteryear the coffee process. See TCP together with UDP), for example
You tin hand the axe farther notice all TPC connexion yesteryear using the tcp pick equally shown below :
Similarly, to notice all opened upwards udp connections you lot tin hand the axe create :
volition listing all procedure amongst opened upwards mesh sockets.
10) How to notice which procedure is using a port
Though you lot tin hand the axe create this amongst netstat ascendency equally well, you lot would last surprised to know that you lot tin hand the axe find all procedure using a detail TCP or UDP port using the lsof command. For instance :
volition notice the procedure which is using TCP or UDP port 19500
You tin hand the axe fifty-fifty names defined inwards etc/services instead of port let out e.g.
volition impress procedure using the SMTP port.
You tin hand the axe also combine TCP together with UDP amongst a port to create to a greater extent than specific search e.g. to notice all procedure inwards UNIX which uses TCP port let out 19600 you lot tin hand the axe create the next :
together with to notice all procedure which is using UDP port 17600 you lot tin hand the axe use
Now that you lot conduct keep seen how to role lsof ascendency to create dissimilar things, let's revise them thence that you lot tin hand the axe recall whatever you lot conduct keep learned thence far. Here is a dainty summary of lsof ascendency examples inwards Linux:
Bonus Tip
You tin hand the axe role the lsof commands to notice all the files are deleted but withal concur the disk space. This is real useful when your disk or filesystem is 100% total together with you lot are looking for files together with directory to delete to gratuitous about space. Suppose /app is your file organization then
$ lsof /app | grep deleted
volition impress all deleted files which are claiming disk space. You tin hand the axe simply kill the procedure which is asset the reference of those files together with acquire dorsum your disk space. The ascendency volition also impress the procedure id to assist you lot kill the process. You tin hand the axe simply kill ascendency for that.
That's all most 10 examples of lsof ascendency inwards UNIX together with Linux. As I said, it's incredibly useful to notice the listing of files opened yesteryear a detail processor to notice all the procedure which holds a lock on a file. Since almost everything is a file inwards UNIX, you lot tin hand the axe role lsof to notice out opened upwards socket, directory, symbolic link, mesh socket, together with many others. You tin hand the axe also run into the lsof human being page for total documentation together with to a greater extent than options.
Further Learning
Linux Command Line Basics
5 Free Linux Courses for Programmers
5 Courses to Learn Shell Scripting for Developers
10 Tips to improve your speed inwards Linux ascendency lines
10 Basic Networking Command Every Linux User Should Know
10 Examples of cURL ascendency inwards Linux
10 Examples of chmod ascendency inwards UNIX
Thanks for reading this article thence far. If you lot notice these lsof commands useful together with then delight portion amongst your friends together with colleagues. If you lot conduct keep whatever questions or feedback together with then delight drib a note.
P. S. - If you lot are serious most improving your Linux skills together with then I also advise you lot await at the Learn Linux inwards v Days together with Level Up Your Career course on Udemy. It's a groovy class for everyone together with you lot volition definitely larn about useful tips to operate meliorate inwards Linux.
It's an incredibly useful tool to create debugging together with troubleshooting inwards UNIX together with Linux environment, together with because of its versatile nature, it's also known equally the "The Swiss Army Knife of Linux". Since most of the production organization runs on the UNIX-based operating system, noesis of this tool croak fifty-fifty to a greater extent than important.
As a Java developer, I oftentimes role lsof command to notice all the files opened my Java process, or about fourth dimension to notice which procedure has opened a detail file e.g. a file which is used to correspond a cache inwards memory, lsof is incredibly useful on doing that.
In this tutorial, nosotros are going to larn dissimilar ways together with options to role lsof about task, which volition farther assist you lot to notice procedure together with file related information inwards UNIX or Linux. You tin hand the axe combine the lsof amongst grep command for advanced search together with filtering.
I oftentimes role grep ascendency to filter output based upon file name, procedure id or file type. If you lot are non familiar amongst basic commands similar grep together with find, together with then I advise you lot conduct keep a await at Linux Command Line Basics on Udemy, a basic class for whatever programmer, tester, information safety people or anyone, who operate on UNIX together with Linux based environment.
How to acquire lsof command
The lsof ascendency mostly comes pre-installed inwards many UNIX systems. If you lot are getting -bash: lsof: ascendency non found an mistake spell using lsof together with then it could last that lsof is non inwards your PATH. Just depository fiscal establishment tally /usr/bin or /usr/sbin folder for this command. If you lot don't notice at that topographic point together with then you lot tin hand the axe install it from source or you lot tin hand the axe inquire your UNIX admin to create that for you.1) How to listing all opened upwards files yesteryear all process
$ lsof
Simply running lsof without whatever declaration impress all opened file together with process. This is non especially useful but a skillful starting point.
2) How to listing all procedure which has opened a file
$ lsof /home/someuser/somefile
volition listing all the procedure which has opened this file. you lot tin hand the axe run into the command, PID, user, together with total file path to find out the process.
3) How to notice all opened files yesteryear a user
You tin hand the axe role lsof -u ascendency to listing all opened file yesteryear a user equally shown below
$ lsof -u username
You tin hand the axe render comma separated listing of users to notice a list of opened upwards files yesteryear multiple users equally shown below
$ lsof -u user1,user2,user3
You tin hand the axe create the same yesteryear providing -u pick multiple times :
$ lsof -u user1 -u user2
If you lot are struggling to recall these lsof ascendency options, hither is a dainty diagram from Julia Evans which volition assist them to remember. If you lot want, you lot tin hand the axe also bring together the Learn The Linux Command Line: Basic Commands, a gratuitous class on Udemy for learning essential Linux commands for FREE.
4) How to listing all files opened yesteryear a detail command
You tin hand the axe role lsof -c pick to render the advert of the ascendency together with listing downwards all the files opened yesteryear that command, for example, to listing all file opened yesteryear java process, you lot tin hand the axe create this :
$ lsof -c java
This is meliorate than using grep for filtering, equally instead of writing lsof | grep java, you lot tin hand the axe simply write lsof -c java.
You tin hand the axe also notice all files opened yesteryear apache which runs as httpd equally shown below :
lsof -c httpd
Just similar multiple users, you lot tin hand the axe also combine multiple processes advert to listing downwards files concur yesteryear them e.g.
$ lsof -c coffee -c httpd
5) How to notice all files opened yesteryear a detail user together with command
You tin hand the axe combine users together with procedure advert inwards i lsof ascendency to listing downwards all the files opened yesteryear a detail procedure or a detail user equally shown below :
$ lsof -u root -c java
This volition listing all files opened or concur yesteryear root user + all files opened yesteryear the coffee process. See TCP together with UDP), for example
$ lsof -i
You tin hand the axe farther notice all TPC connexion yesteryear using the tcp pick equally shown below :
$ lsof -i tcp
Similarly, to notice all opened upwards udp connections you lot tin hand the axe create :
$ lsof -i udp
volition listing all procedure amongst opened upwards mesh sockets.
10) How to notice which procedure is using a port
Though you lot tin hand the axe create this amongst netstat ascendency equally well, you lot would last surprised to know that you lot tin hand the axe find all procedure using a detail TCP or UDP port using the lsof command. For instance :
$ lsof -i :19500
volition notice the procedure which is using TCP or UDP port 19500
You tin hand the axe fifty-fifty names defined inwards etc/services instead of port let out e.g.
$ lsof -i :smtp
volition impress procedure using the SMTP port.
You tin hand the axe also combine TCP together with UDP amongst a port to create to a greater extent than specific search e.g. to notice all procedure inwards UNIX which uses TCP port let out 19600 you lot tin hand the axe create the next :
$ lsof -i tcp:19600
together with to notice all procedure which is using UDP port 17600 you lot tin hand the axe use
$ lsof -i udp:17600
Now that you lot conduct keep seen how to role lsof ascendency to create dissimilar things, let's revise them thence that you lot tin hand the axe recall whatever you lot conduct keep learned thence far. Here is a dainty summary of lsof ascendency examples inwards Linux:
Bonus Tip
You tin hand the axe role the lsof commands to notice all the files are deleted but withal concur the disk space. This is real useful when your disk or filesystem is 100% total together with you lot are looking for files together with directory to delete to gratuitous about space. Suppose /app is your file organization then
$ lsof /app | grep deleted
volition impress all deleted files which are claiming disk space. You tin hand the axe simply kill the procedure which is asset the reference of those files together with acquire dorsum your disk space. The ascendency volition also impress the procedure id to assist you lot kill the process. You tin hand the axe simply kill ascendency for that.
That's all most 10 examples of lsof ascendency inwards UNIX together with Linux. As I said, it's incredibly useful to notice the listing of files opened yesteryear a detail processor to notice all the procedure which holds a lock on a file. Since almost everything is a file inwards UNIX, you lot tin hand the axe role lsof to notice out opened upwards socket, directory, symbolic link, mesh socket, together with many others. You tin hand the axe also run into the lsof human being page for total documentation together with to a greater extent than options.
Further Learning
Linux Command Line Basics
5 Free Linux Courses for Programmers
5 Courses to Learn Shell Scripting for Developers
10 Tips to improve your speed inwards Linux ascendency lines
10 Basic Networking Command Every Linux User Should Know
10 Examples of cURL ascendency inwards Linux
10 Examples of chmod ascendency inwards UNIX
Thanks for reading this article thence far. If you lot notice these lsof commands useful together with then delight portion amongst your friends together with colleagues. If you lot conduct keep whatever questions or feedback together with then delight drib a note.
P. S. - If you lot are serious most improving your Linux skills together with then I also advise you lot await at the Learn Linux inwards v Days together with Level Up Your Career course on Udemy. It's a groovy class for everyone together with you lot volition definitely larn about useful tips to operate meliorate inwards Linux.
Belum ada Komentar untuk "10 Representative Of Lsof Commands Inwards Unix As Well As Linux"
Posting Komentar