View network activity of any application or user in realtime

lsof -r 2 -p PID -i -a
The "-r 2" option puts lsof in repeat mode, with updates every 2 seconds. (Ctrl -c quits) The "-p" option is used to specify the application PID you want to monitor. The "-u' option can be used to keep an eye on a users network activity. "lsof -r 2 -u username -i -a"

15
By: zlemini
2010-03-16 20:37:16

These Might Interest You

  • View details of both TCP and UDP network activity within a specified port range. Show Sample Output


    5
    lsof -i :555-7000
    zlemini · 2010-10-07 20:45:54 0
  • View all files opened by a user in specified directory. The +D option makes lsof search all sub-directories to complete depth, while ignoring symbolic links.


    16
    sudo lsof -u someuser -a +D /etc
    zlemini · 2010-06-11 06:37:27 0
  • Shows a constantly updating display of disk IO activity. Two sections are in the output. The first is the IO activity since the machine was booted, the second section is the IO activity in the last second Show Sample Output


    0
    watch -n 1 'iostat -xmd 1 2'
    ryanchapman · 2013-07-06 08:07:32 0
  • connect to it with any network command (including web browser - if you don't mind weird formatting) curl 127.0.0.1:9876 nc 127.0.0.1 9876 Show Sample Output


    5
    mkfifo /tmp/view; nc -l 9876 < /tmp/view& script -f /tmp/view
    snipertyler · 2014-06-23 05:06:13 1

What Others Think

I never get tired of lsof. really, what an awesome tool.
linuxrawkstar · 431 weeks and 2 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

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.

Share Your Commands



Stay in the loop…

Follow the Tweets.

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

Subscribe to the feeds.

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: