show only the name of the apps that are using internet Show Sample Output
This command is more portable than it's cousin netstat. It works well on all the BSDs, GNU/Linux, AIX and Mac OS X. You won't find lsof by default on Solaris or HPUX by default, but packages exist around the web for installation, if needed, and the command works as shown. This is the most portable command I can find that lists listening ports and their associated pid. Show Sample Output
List all file opened by a particular command based on it's command name. Show Sample Output
It may be helpful in case you need to umount a directory and some process is preventing you to do so keeping the folder busy. The lsof may process the +D option slowly and may require a significant amount of memory because it will descend the full dir tree. On the other hand it will neither follow symlinks nor other file systems.
Just refining last proposal for this check, showing awk power to make more complex math (instead /1024/1024, 2^20). We don't need declare variable before run lsof, because $(command) returns his output. Also, awk can perform filtering by regexp instead to call grep. I changed the 0.0000xxxx messy output, with a more readable form purging all fractional numbers and files less than 1 MB. Show Sample Output
Instead of using force un-mounting, it's better to find the processes that currently use the relevant folder. Taken from: http://www.linuxhowtos.org/Tips%20and%20Tricks/findprocesses.htm Show Sample Output
While `lsof` will work, why not use the tool designed explicitly for this job? (If not run as root, you will only see the names of PID you own) Show Sample Output
Imagine you've started a long-running process that involves piping data,
but you forgot to add the progress-bar option to a command.
e.g.
xz -dc bigdata.xz | complicated-processing-program > summary
.
This command uses lsof to see how much data xz has read from the file.
lsof -o0 -o -Fo FILENAME
Display offsets (-o), in decimal (-o0), in parseable form (-Fo)
This will output something like:
.
p12607
f3
o0t45187072
.
Process id (p), File Descriptor (f), Offset (o)
.
We stat the file to get its size
stat -c %s FILENAME
.
Then we plug the values into awk.
Split the line at the letter t: -Ft
Define a variable for the file's size: -s=$(stat...)
Only work on the offset line: /^o/
.
Note this command was tested using the Linux version of lsof.
Because it uses lsof's batch option (-F) it may be portable.
.
Thanks to @unhammer for the brilliant idea.
Show Sample Output
Lis all files opened by a particular process id. "PID" Show Sample Output
Check which files are opened by Firefox then sort by largest size (in MB). You can see all files opened by just replacing grep to "/". Useful if you'd like to debug and check which extensions or files are taking too much memory resources in Firefox. Show Sample Output
When trying to play a sound you may sometimes get an error saying that your sound card is already used, but not by what process. This will list all processes playing sound, useful to kill processes that you no longer need but that keep using your sound card. Show Sample Output
change 24073 to your pid Show Sample Output
for when a program is hogging the sound output. finds, and kills. add -9 to the end for wedged processes. add in 'grep ^program' after lsof to filter. Show Sample Output
The output of lsof is piped to txt2html which converts it to html. # Perl module HTML::TextToHTML needed Show Sample Output
Maybe this will help you to monitor your load balancers or reverse proxies if you happen to use them. This is useful to discover TIME OUTS and this will let you know if one or more of your application servers is not connected by checking. Show Sample Output
also could specify port number: lsof -ni TCP:80
Fast and easy way to find all established tcp connections without using the netstat command.
Say you're started "xzcat bigdata.xz | complicated-processing-program >summary" an hour ago, and you of course forgot to enable progress output (you could've just put "awk 'NR%1000==0{print NR>"/dev/stderr"}{print}'" in the pipeline but it's too late for that now). But you really want some idea of how far along your program is. Then you can run the above command to see how many % along xzcat is in reading the file. Note that this is for the GNU/Linux version of lsof; the one found on e.g. Darwin has slightly different output so the awk part may need some tweaks. Show Sample Output
In addition to generating the current connections, it also opens then in your default browser on gnome.
Check open TCP and UDP ports Show Sample Output
See the summary. Show Sample Output
While the posted solution works, I'm a bit uneasy about the "%d" part. This would be hyper-correct approach:
lsof|gawk '$4~/txt/{next};/REG.*\(deleted\)$/{sub(/.$/,"",$4);printf ">/proc/%s/fd/%s\n", $2,$4}'
Oh, and you gotta pipe the result to sh if you want it to actually trim the files. ;)
Btw, this approach also removes false negatives (OP's command skips any deleted files with "txt" in their name).
commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.
Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.
» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10
Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):
Subscribe to the feed for: