11 September, 2015

How to find list of all open files in Linux/UNIX

How to find list of all open files in Linux/UNIX


Its really very simple to find the list of open files on UNIX/Linux. As you know linux/unix kernel has many powerful commands which helps a lot.

For checking the list of all open files on your system, you can use the command

Command :-

lsof

lsof - list open files , this has many command options.Some important options as below :

-p - for specific PID
-u - for specific user


Example :-

lsof -u manoj


Output :-

lsof      9963 manoj  mem       REG                8,1     52120 11276171 /lib/x86_64-linux-gnu/libnss_files-2.15.so
lsof      9963 manoj  mem       REG                8,1     47680 11276175 /lib/x86_64-linux-gnu/libnss_nis-2.15.so
lsof      9963 manoj  mem       REG                8,1     97248 11276165 /lib/x86_64-linux-gnu/libnsl-2.15.so
lsof      9963 manoj  mem       REG                8,1     35680 11276167 /lib/x86_64-linux-gnu/libnss_compat-2.15.so
lsof      9963 manoj  mem       REG                8,1   7224832  5511486 /usr/lib/locale/locale-archive
lsof      9963 manoj  mem       REG                8,1   1815224 11276120 /lib/x86_64-linux-gnu/libc-2.15.so
lsof      9963 manoj  mem       REG                8,1    149280 11276100 /lib/x86_64-linux-gnu/ld-2.15.so
lsof      9963 manoj  mem       REG                8,1     26258  5769171 /usr/lib/x86_64-linux-gnu/gconv/gconv-modules.cache
lsof      9963 manoj    0u      CHR              136,0       0t0        3 /dev/pts/0
lsof      9963 manoj    1u      CHR              136,0       0t0        3 /dev/pts/0
lsof      9963 manoj    2u      CHR              136,0       0t0        3 /dev/pts/0
lsof      9963 manoj    3r      DIR                0,3         0        1 /proc
lsof      9963 manoj    4r      DIR                0,3         0    64363 /proc/9963/fd
lsof      9963 manoj    5w     FIFO                0,8       0t0    64368 pipe
lsof      9963 manoj    6r     FIFO                0,8       0t0    64369 pipe
lsof      9964 manoj  cwd       DIR                8,1      4096  3932162 /home/manoj
lsof      9964 manoj  rtd       DIR                8,1      4096        2 /
lsof      9964 manoj  txt       REG                8,1    131312  5505664 /usr/bin/lsof
lsof      9964 manoj  mem       REG                8,1     52120 11276171 /lib/x86_64-linux-gnu/libnss_files-2.15.so
lsof      9964 manoj  mem       REG                8,1     47680 11276175 /lib/x86_64-linux-gnu/libnss_nis-2.15.so
lsof      9964 manoj  mem       REG                8,1     97248 11276165 /lib/x86_64-linux-gnu/libnsl-2.15.so
lsof      9964 manoj  mem       REG                8,1     35680 11276167 /lib/x86_64-linux-gnu/libnss_compat-2.15.so
lsof      9964 manoj  mem       REG                8,1   7224832  5511486 /usr/lib/locale/locale-archive
lsof      9964 manoj  mem       REG                8,1   1815224 11276120 /lib/x86_64-linux-gnu/libc-2.15.so
lsof      9964 manoj  mem       REG                8,1    149280 11276100 /lib/x86_64-linux-gnu/ld-2.15.so


Apart from there are many other options you can use to find more powerful lsof command.

Example 2:-

manoj@manoj-HP-ProBook-6450b:~$ ps -ef | lsof -p 9987
COMMAND    PID USER   FD      TYPE DEVICE SIZE/OFF NODE NAME
kworker/u 9987 root  cwd   unknown                      /proc/9987/cwd (readlink: Permission denied)
kworker/u 9987 root  rtd   unknown                      /proc/9987/root (readlink: Permission denied)
kworker/u 9987 root  txt   unknown                      /proc/9987/exe (readlink: Permission denied)
kworker/u 9987 root NOFD                                /proc/9987/fd (opendir: Permission denied)




Hope it will help you.
Follow for more details on Google+ and @Facebook!!!

Find More :-

No comments:

Post a Comment