List all files opened by a particular command

lsof -c dhcpd
List all file opened by a particular command based on it's command name.
Sample Output
[root@kxct1 prod]# lsof -c dhcpd
COMMAND   PID USER   FD   TYPE             DEVICE    SIZE      NODE NAME
dhcpd   15857 root  cwd    DIR                8,2    4096         2 /
dhcpd   15857 root  rtd    DIR                8,2    4096         2 /
dhcpd   15857 root  txt    REG                8,2  678400    475389 /usr/sbin/dhcpd
dhcpd   15857 root  mem    REG                8,2  105080   1033986 /lib64/ld-2.3.4.so
dhcpd   15857 root  mem    REG                8,2 1493186   1033987 /lib64/tls/libc-2.3.4.so
dhcpd   15857 root  mem    REG                8,2   56902   1032222 /lib64/libnss_files-2.3.4.so
dhcpd   15857 root    0w   REG               8,17   63282   3287672 /var/lib/dhcp/dhcpd.leases
dhcpd   15857 root    3u  unix 0x0000010110312680         717501116 socket
dhcpd   15857 root    4u   raw                            717501119 00000000:0001->00000000:0000 st=07
dhcpd   15857 root    6u  IPv4          717501138               UDP *:bootps
dhcpd   15857 root    7u  sock                0,4         717501137 can't identify protocol

25
By: d4n3sh
2009-04-17 07:18:38

These Might Interest You

  • Just type 'opened' and get all files currently opened for edit.


    0
    alias opened='p4 opened | awk -F# "{print \$1}"'
    Alexander · 2009-03-20 11:06:41 0
  • Lis all files opened by a particular process id. "PID" Show Sample Output


    6
    lsof -p 15857
    d4n3sh · 2009-04-17 07:16:03 0
  • in loop, until the last port (65535), list all opened ports on host. in the sample I used localhost, but you can replace with any host to test. Show Sample Output


    1
    time { i=0; while [ $(( i < 65535 )) -eq 1 ] ; do nc -zw2 localhost $((++i)) && echo port $i opened ; done; }
    glaudiston · 2009-12-09 17:33:47 4
  • Tail all logs that are opened by all java processes. This is helpful when you are on a new environment and you do not know where the logs are located. Instead of java you can put any process name. This command does work only for Linux. The list of all log files opened by java process: sudo ls -l $(eval echo "/proc/{$(echo $(pgrep java)|sed 's/ /,/')}/fd/")|grep log|sed 's/[^/]* //g'


    -1
    sudo ls -l $(eval echo "/proc/{$(echo $(pgrep java)|sed 's/ /,/')}/fd/")|grep log|sed 's/[^/]* //g'|xargs -r tail -f
    vutcovici · 2010-07-30 18:20:00 0

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: