10 Illustration Of Lsof Commands Inwards Unix As Well As Linux
Sunday, February 18, 2018
Add Comment
It's been a long fourth dimension since I guide keep written anything on UNIX or Linux, but today I'll verbalise most the lsof command, a utility dominance every organization admin in addition to developers love. The lsof dominance stands for listing opened upwards file descriptors in addition to equally the advert suggests, it is used to discovery opened upwards files past times process. Since almost everything inward UNIX are file, yous tin piece of occupation lsof dominance to discovery 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 graphic symbol special file, a regular pipe, a named pipe, an network socket, a UNIX domain socket in addition to many others. I guide keep mostly used it to discovery all the files opened past times a item process, which I volition exhibit yous inward the coming section.
It's an incredibly useful tool to produce debugging in addition to troubleshooting inward UNIX in addition to Linux environment, in addition to 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 acquire fifty-fifty to a greater extent than important.
As a Java developer, I ofttimes piece of occupation lsof command to discovery all the files opened my Java process, or to a greater extent than or less fourth dimension to discovery which procedure has opened a item file e.g. a file which is used to correspond a cache inward memory, lsof is incredibly useful on doing that.
In this tutorial, nosotros are going to larn dissimilar ways in addition to options to piece of occupation lsof to a greater extent than or less task, which volition farther aid yous to discovery procedure in addition to file related information inward UNIX or Linux. You tin combine the lsof amongst grep command for advanced search in addition to filtering.
I ofttimes piece of occupation grep dominance to filter output based upon file name, procedure id or file type. If yous are non familiar amongst basic commands similar grep in addition to find, therefore I propose yous accept a await at Linux Command Line Basics, a basic course of written report for whatsoever programmer, tester, information safety people or anyone, who piece of occupation on UNIX in addition to Linux based environment.
1) How to listing all opened upwards files past times all process
Simply running lsof without whatsoever declaration impress all opened file in addition to process. This is non specially useful but a proficient starting point.
2) How to listing all procedure which has opened a file
volition listing all the procedure which has opened this file. yous tin run across the command, PID, user in addition to total file path to find out the process.
3) How to discovery all opened files past times a user
You tin piece of occupation lsof -u dominance to listing all opened file past times a user equally shown below
You tin supply comma separated listing of users to discovery a list of opened upwards files past times multiple users equally shown below
You tin produce the same past times providing -u choice multiple times :
If yous are struggling to retrieve these lsof dominance options, hither is a squeamish diagram from Julia Evans which volition aid them to remember. If yous want, yous tin also accept a impress out of this in addition to perish along at your desk for quick reference:
4) How to listing all files opened past times a item command
You tin piece of occupation lsof -c choice to supply the advert of the dominance in addition to listing downward all the files opened past times that command, for example, to listing all file opened past times java process, yous tin produce this :
This is improve than using grep for filtering, equally instead of writing lsof | grep java, yous tin merely write lsof -c java.
You tin also discovery all files opened past times apache which runs as httpd equally shown below :
Just similar multiple users, yous tin also combine multiple processes advert to listing downward files concur past times them e.g.
5) How to discovery all files opened past times a item user in addition to command
You tin combine users in addition to procedure advert inward 1 lsof dominance to listing downward all the files opened past times a item procedure or a item user equally shown below :
This volition listing all files opened or concur past times root user + all files opened past times the coffee process. See TCP in addition to UDP), for example
You tin farther discovery all TPC connectedness past times using the tcp choice equally shown below :
Similarly, to discovery all opened upwards udp connections yous tin produce :
volition listing all procedure amongst opened upwards network sockets.
10) How to discovery which procedure is using a port
Though yous tin produce this amongst netstat dominance equally well, yous would survive surprised to know that yous tin find all procedure using a item TCP or UDP port using the lsof command. For instance :
volition discovery the procedure which is using TCP or UDP port 19500
You tin fifty-fifty names defined inward etc/services instead of port position out e.g.
volition impress procedure using the SMTP port.
You tin also combine TCP in addition to UDP amongst a port to produce to a greater extent than specific search e.g. to discovery all procedure inward UNIX which are uses TCP port position out 19600 yous tin produce next :
in addition to to discovery all procedure which is using UDP port 17600 yous tin use
Now that yous guide keep seen how to piece of occupation lsof dominance to produce dissimilar things, let's revise them therefore that yous tin retrieve whatever yous guide keep learned therefore far. Here is a squeamish summary of lsof dominance examples inward Linux:
That's all most 10 examples of lsof dominance inward UNIX in addition to Linux. As I said, it's incredibly useful to discovery the listing of files opened past times a item processor to discovery all the procedure which holds a lock on a file. Since almost everything is a file inward UNIX, yous tin piece of occupation lsof to discovery out opened upwards socket, directory, symbolic link, network socket in addition to many others. You tin also run across the lsof human being page for total documentation in addition to 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 inward Linux dominance lines
Thanks for reading this article therefore far. If yous discovery these lsof commands useful therefore delight percentage amongst your friends in addition to colleagues. If yous guide keep whatsoever questions or feedback therefore delight drib a note.
Sumber https://javarevisited.blogspot.com/
It's an incredibly useful tool to produce debugging in addition to troubleshooting inward UNIX in addition to Linux environment, in addition to 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 acquire fifty-fifty to a greater extent than important.
As a Java developer, I ofttimes piece of occupation lsof command to discovery all the files opened my Java process, or to a greater extent than or less fourth dimension to discovery which procedure has opened a item file e.g. a file which is used to correspond a cache inward memory, lsof is incredibly useful on doing that.
In this tutorial, nosotros are going to larn dissimilar ways in addition to options to piece of occupation lsof to a greater extent than or less task, which volition farther aid yous to discovery procedure in addition to file related information inward UNIX or Linux. You tin combine the lsof amongst grep command for advanced search in addition to filtering.
I ofttimes piece of occupation grep dominance to filter output based upon file name, procedure id or file type. If yous are non familiar amongst basic commands similar grep in addition to find, therefore I propose yous accept a await at Linux Command Line Basics, a basic course of written report for whatsoever programmer, tester, information safety people or anyone, who piece of occupation on UNIX in addition to Linux based environment.
How to acquire lsof command
The lsof dominance to a greater extent than ofttimes than non comes pre-installed inward many UNIX systems. If yous are getting -bash: lsof: dominance non found an fault spell using lsof therefore it could survive that lsof is non inward your PATH. Just banking concern jibe /usr/bin or /usr/sbin folder for this command. If yous don't discovery in that place therefore yous tin install it from source or yous tin enquire your UNIX admin to produce that for you.1) How to listing all opened upwards files past times all process
$ lsof
Simply running lsof without whatsoever declaration impress all opened file in addition to process. This is non specially useful but a proficient 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. yous tin run across the command, PID, user in addition to total file path to find out the process.
3) How to discovery all opened files past times a user
You tin piece of occupation lsof -u dominance to listing all opened file past times a user equally shown below
$ lsof -u username
You tin supply comma separated listing of users to discovery a list of opened upwards files past times multiple users equally shown below
$ lsof -u user1,user2,user3
You tin produce the same past times providing -u choice multiple times :
$ lsof -u user1 -u user2
If yous are struggling to retrieve these lsof dominance options, hither is a squeamish diagram from Julia Evans which volition aid them to remember. If yous want, yous tin also accept a impress out of this in addition to perish along at your desk for quick reference:
4) How to listing all files opened past times a item command
You tin piece of occupation lsof -c choice to supply the advert of the dominance in addition to listing downward all the files opened past times that command, for example, to listing all file opened past times java process, yous tin produce this :
$ lsof -c java
This is improve than using grep for filtering, equally instead of writing lsof | grep java, yous tin merely write lsof -c java.
You tin also discovery all files opened past times apache which runs as httpd equally shown below :
lsof -c httpd
Just similar multiple users, yous tin also combine multiple processes advert to listing downward files concur past times them e.g.
$ lsof -c coffee -c httpd
5) How to discovery all files opened past times a item user in addition to command
You tin combine users in addition to procedure advert inward 1 lsof dominance to listing downward all the files opened past times a item procedure or a item user equally shown below :
$ lsof -u root -c java
This volition listing all files opened or concur past times root user + all files opened past times the coffee process. See TCP in addition to UDP), for example
$ lsof -i
You tin farther discovery all TPC connectedness past times using the tcp choice equally shown below :
$ lsof -i tcp
Similarly, to discovery all opened upwards udp connections yous tin produce :
$ lsof -i udp
volition listing all procedure amongst opened upwards network sockets.
10) How to discovery which procedure is using a port
Though yous tin produce this amongst netstat dominance equally well, yous would survive surprised to know that yous tin find all procedure using a item TCP or UDP port using the lsof command. For instance :
$ lsof -i :19500
volition discovery the procedure which is using TCP or UDP port 19500
You tin fifty-fifty names defined inward etc/services instead of port position out e.g.
$ lsof -i :smtp
volition impress procedure using the SMTP port.
You tin also combine TCP in addition to UDP amongst a port to produce to a greater extent than specific search e.g. to discovery all procedure inward UNIX which are uses TCP port position out 19600 yous tin produce next :
$ lsof -i tcp:19600
in addition to to discovery all procedure which is using UDP port 17600 yous tin use
$ lsof -i udp:17600
Now that yous guide keep seen how to piece of occupation lsof dominance to produce dissimilar things, let's revise them therefore that yous tin retrieve whatever yous guide keep learned therefore far. Here is a squeamish summary of lsof dominance examples inward Linux:
That's all most 10 examples of lsof dominance inward UNIX in addition to Linux. As I said, it's incredibly useful to discovery the listing of files opened past times a item processor to discovery all the procedure which holds a lock on a file. Since almost everything is a file inward UNIX, yous tin piece of occupation lsof to discovery out opened upwards socket, directory, symbolic link, network socket in addition to many others. You tin also run across the lsof human being page for total documentation in addition to 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 inward Linux dominance lines
Thanks for reading this article therefore far. If yous discovery these lsof commands useful therefore delight percentage amongst your friends in addition to colleagues. If yous guide keep whatsoever questions or feedback therefore delight drib a note.
0 Response to "10 Illustration Of Lsof Commands Inwards Unix As Well As Linux"
Post a Comment