2 Answers
2

There are two reasons lsof | wc -l doesn't count file descriptors. One is that it lists things that aren't open files, such as loaded dynamically linked libraries and current working directories; you need to filter them out. Another is that lsof takes some time to run, so can miss files that are opened or closed while it's running; therefore the number of listed open files is approximate. Looking at /proc/sys/fs/file-nr gives you an exact value at a particular point in time.

cat /proc/sys/fs/file-nr is only useful when you need the exact figure, mainly to check for resource exhaustion. If you want to list the open files, you need to call lsof, or use some equivalent method such as trawling /proc/*/fd manually.

Hi thanks for giving a good explanation Gilles. I tried ls /proc/*/fd and got all the open fd's at that time. Its producing an output with some color coding, I'll just have to look at the manual.
–
dimasFeb 27 '13 at 1:40

@dimas /proc/*/fd directories contain symbolic links to the open files. For visual inspection, use ls -l. For automated treatment, use readlink to extract the link target.
–
GillesFeb 27 '13 at 1:44