10 Event Of Lsof Commands Inwards Unix In Addition To Linux
It's been a long fourth dimension since I conduct maintain written anything on UNIX or Linux commands, but today I'll verbalize almost the lsof command, a utility ascendancy every organisation admin too developers love. The lsof ascendancy stands for listing opened upwards file descriptors too equally the get upwards suggests, it is used to abide by opened upwards files past times process. Since almost everything inwards UNIX are file, y'all tin piece of job lsof ascendancy to abide by 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, too many others. I conduct maintain mostly used it to abide by all the files opened past times a detail process, which I volition present y'all inwards the coming section.
It's an incredibly useful tool to produce debugging too troubleshooting inwards UNIX too Linux environment, too because of its versatile nature, it's also known equally the "The Swiss Army Knife of Linux". Since most of the production organisation runs on the UNIX-based operating system, cognition of this tool cash inwards one's chips fifty-fifty to a greater extent than important.
As a Java developer, I oft piece of job lsof command to abide by all the files opened my Java process, or merely about fourth dimension to abide by which procedure has opened a detail file e.g. a file which is used to stand upwards for a cache inwards memory, lsof is incredibly useful on doing that.
In this tutorial, nosotros are going to larn dissimilar ways too options to piece of job lsof merely about task, which volition farther aid y'all to abide by procedure too file related information inwards UNIX or Linux. You tin combine the lsof amongst grep command for advanced search too filtering.
I oft piece of job grep ascendancy to filter output based upon file name, procedure id or file type. If y'all are non familiar amongst basic commands similar grep too find, thence I advise y'all conduct maintain a expect at Linux Command Line Basics on Udemy, a basic course of teaching for whatever programmer, tester, information safety people or anyone, who piece of job on UNIX too Linux based environment.
1) How to listing all opened upwards files past times all process
Simply running lsof without whatever declaration impress all opened file too process. This is non peculiarly useful but a expert starting point.
2) How to listing all procedure which has opened a file
volition listing all the procedure which has opened this file. y'all tin run into the command, PID, user, too total file path to find out the process.
3) How to abide by all opened files past times a user
You tin piece of job lsof -u ascendancy to listing all opened file past times a user equally shown below
You tin render comma separated listing of users to abide by a list of opened upwards files past times multiple users equally shown below
You tin produce the same past times providing -u pick multiple times :
If y'all are struggling to squall back these lsof ascendancy options, hither is a dainty diagram from Julia Evans which volition aid them to remember. If y'all want, y'all tin also bring together the Learn The Linux Command Line: Basic Commands, a costless course of teaching on Udemy for learning essential Linux commands for FREE.
4) How to listing all files opened past times a detail command
You tin piece of job lsof -c pick to render the get upwards of the ascendancy too listing downward all the files opened past times that command, for example, to listing all file opened past times java process, y'all tin produce this :
This is meliorate than using grep for filtering, equally instead of writing lsof | grep java, y'all tin merely write lsof -c java.
You tin also abide by all files opened past times apache which runs as httpd equally shown below :
Just similar multiple users, y'all tin also combine multiple processes get upwards to listing downward files agree past times them e.g.
5) How to abide by all files opened past times a detail user too command
You tin combine users too procedure get upwards inwards i lsof ascendancy to listing downward all the files opened past times a detail procedure or a detail user equally shown below :
This volition listing all files opened or agree past times root user + all files opened past times the coffee process. See TCP too UDP), for example
You tin farther abide by all TPC connectedness past times using the tcp pick equally shown below :
Similarly, to abide by all opened upwards udp connections y'all tin produce :
volition listing all procedure amongst opened upwards network sockets.
10) How to abide by which procedure is using a port
Though y'all tin produce this amongst netstat ascendancy equally well, y'all would hold upwards surprised to know that y'all tin find all procedure using a detail TCP or UDP port using the lsof command. For event :
volition abide by the procedure which is using TCP or UDP port 19500
You tin fifty-fifty names defined inwards etc/services instead of port give away e.g.
volition impress procedure using the SMTP port.
You tin also combine TCP too UDP amongst a port to produce to a greater extent than specific search e.g. to abide by all procedure inwards UNIX which uses TCP port give away 19600 y'all tin produce the next :
too to abide by all procedure which is using UDP port 17600 y'all tin use
Now that y'all conduct maintain seen how to piece of job lsof ascendancy to produce dissimilar things, let's revise them thence that y'all tin squall back whatever y'all conduct maintain learned thence far. Here is a dainty summary of lsof ascendancy examples inwards Linux:
Bonus Tip
You tin piece of job the lsof commands to abide by all the files are deleted but yet agree the disk space. This is rattling useful when your disk or filesystem is 100% total too y'all are looking for files too directory to delete to costless merely about space. Suppose /app is your file organisation then
$ lsof /app | grep deleted
volition impress all deleted files which are claiming disk space. You tin merely kill the procedure which is belongings the reference of those files too acquire dorsum your disk space. The ascendancy volition also impress the procedure id to aid y'all kill the process. You tin merely kill ascendancy for that.
That's all almost 10 examples of lsof ascendancy inwards UNIX too Linux. As I said, it's incredibly useful to abide by the listing of files opened past times a detail processor to abide by all the procedure which holds a lock on a file. Since almost everything is a file inwards UNIX, y'all tin piece of job lsof to abide by out opened upwards socket, directory, symbolic link, network socket, too many others. You tin also run into the lsof human page for total documentation too 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 ascendancy lines
10 Basic Networking Command Every Linux User Should Know
10 Examples of cURL ascendancy inwards Linux
10 Examples of chmod ascendancy inwards UNIX
Thanks for reading this article thence far. If y'all abide by these lsof commands useful thence delight portion amongst your friends too colleagues. If y'all conduct maintain whatever questions or feedback thence delight drib a note.
P. S. - If y'all are serious almost improving your Linux skills thence I also advise y'all expect at the Learn Linux inwards five Days too Level Up Your Career course on Udemy. It's a cracking course of teaching for everyone too y'all volition definitely larn merely about useful tips to piece of job meliorate inwards Linux.
It's an incredibly useful tool to produce debugging too troubleshooting inwards UNIX too Linux environment, too because of its versatile nature, it's also known equally the "The Swiss Army Knife of Linux". Since most of the production organisation runs on the UNIX-based operating system, cognition of this tool cash inwards one's chips fifty-fifty to a greater extent than important.
As a Java developer, I oft piece of job lsof command to abide by all the files opened my Java process, or merely about fourth dimension to abide by which procedure has opened a detail file e.g. a file which is used to stand upwards for a cache inwards memory, lsof is incredibly useful on doing that.
In this tutorial, nosotros are going to larn dissimilar ways too options to piece of job lsof merely about task, which volition farther aid y'all to abide by procedure too file related information inwards UNIX or Linux. You tin combine the lsof amongst grep command for advanced search too filtering.
I oft piece of job grep ascendancy to filter output based upon file name, procedure id or file type. If y'all are non familiar amongst basic commands similar grep too find, thence I advise y'all conduct maintain a expect at Linux Command Line Basics on Udemy, a basic course of teaching for whatever programmer, tester, information safety people or anyone, who piece of job on UNIX too Linux based environment.
How to acquire lsof command
The lsof ascendancy mostly comes pre-installed inwards many UNIX systems. If y'all are getting -bash: lsof: ascendancy non found an fault piece using lsof thence it could hold upwards that lsof is non inwards your PATH. Just banking concern jibe /usr/bin or /usr/sbin folder for this command. If y'all don't abide by at that topographic point thence y'all tin install it from source or y'all tin inquire 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 whatever declaration impress all opened file too process. This is non peculiarly useful but a expert 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. y'all tin run into the command, PID, user, too total file path to find out the process.
3) How to abide by all opened files past times a user
You tin piece of job lsof -u ascendancy to listing all opened file past times a user equally shown below
$ lsof -u username You tin render comma separated listing of users to abide by 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 pick multiple times :
$ lsof -u user1 -u user2
If y'all are struggling to squall back these lsof ascendancy options, hither is a dainty diagram from Julia Evans which volition aid them to remember. If y'all want, y'all tin also bring together the Learn The Linux Command Line: Basic Commands, a costless course of teaching on Udemy for learning essential Linux commands for FREE.
4) How to listing all files opened past times a detail command
You tin piece of job lsof -c pick to render the get upwards of the ascendancy too listing downward all the files opened past times that command, for example, to listing all file opened past times java process, y'all tin produce this :
$ lsof -c java This is meliorate than using grep for filtering, equally instead of writing lsof | grep java, y'all tin merely write lsof -c java.
You tin also abide by all files opened past times apache which runs as httpd equally shown below :
lsof -c httpd Just similar multiple users, y'all tin also combine multiple processes get upwards to listing downward files agree past times them e.g.
$ lsof -c coffee -c httpd
5) How to abide by all files opened past times a detail user too command
You tin combine users too procedure get upwards inwards i lsof ascendancy to listing downward all the files opened past times a detail procedure or a detail user equally shown below :
$ lsof -u root -c java
This volition listing all files opened or agree past times root user + all files opened past times the coffee process. See TCP too UDP), for example
$ lsof -i
You tin farther abide by all TPC connectedness past times using the tcp pick equally shown below :
$ lsof -i tcp
Similarly, to abide by all opened upwards udp connections y'all tin produce :
$ lsof -i udp
volition listing all procedure amongst opened upwards network sockets.
10) How to abide by which procedure is using a port
Though y'all tin produce this amongst netstat ascendancy equally well, y'all would hold upwards surprised to know that y'all tin find all procedure using a detail TCP or UDP port using the lsof command. For event :
$ lsof -i :19500
volition abide by the procedure which is using TCP or UDP port 19500
You tin fifty-fifty names defined inwards etc/services instead of port give away e.g.
$ lsof -i :smtp
volition impress procedure using the SMTP port.
You tin also combine TCP too UDP amongst a port to produce to a greater extent than specific search e.g. to abide by all procedure inwards UNIX which uses TCP port give away 19600 y'all tin produce the next :
$ lsof -i tcp:19600
too to abide by all procedure which is using UDP port 17600 y'all tin use
$ lsof -i udp:17600
Now that y'all conduct maintain seen how to piece of job lsof ascendancy to produce dissimilar things, let's revise them thence that y'all tin squall back whatever y'all conduct maintain learned thence far. Here is a dainty summary of lsof ascendancy examples inwards Linux:
Bonus Tip
You tin piece of job the lsof commands to abide by all the files are deleted but yet agree the disk space. This is rattling useful when your disk or filesystem is 100% total too y'all are looking for files too directory to delete to costless merely about space. Suppose /app is your file organisation then
$ lsof /app | grep deleted
volition impress all deleted files which are claiming disk space. You tin merely kill the procedure which is belongings the reference of those files too acquire dorsum your disk space. The ascendancy volition also impress the procedure id to aid y'all kill the process. You tin merely kill ascendancy for that.
That's all almost 10 examples of lsof ascendancy inwards UNIX too Linux. As I said, it's incredibly useful to abide by the listing of files opened past times a detail processor to abide by all the procedure which holds a lock on a file. Since almost everything is a file inwards UNIX, y'all tin piece of job lsof to abide by out opened upwards socket, directory, symbolic link, network socket, too many others. You tin also run into the lsof human page for total documentation too 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 ascendancy lines
10 Basic Networking Command Every Linux User Should Know
10 Examples of cURL ascendancy inwards Linux
10 Examples of chmod ascendancy inwards UNIX
Thanks for reading this article thence far. If y'all abide by these lsof commands useful thence delight portion amongst your friends too colleagues. If y'all conduct maintain whatever questions or feedback thence delight drib a note.
P. S. - If y'all are serious almost improving your Linux skills thence I also advise y'all expect at the Learn Linux inwards five Days too Level Up Your Career course on Udemy. It's a cracking course of teaching for everyone too y'all volition definitely larn merely about useful tips to piece of job meliorate inwards Linux.


0 Response to "10 Event Of Lsof Commands Inwards Unix In Addition To Linux"
Post a Comment