When running tail -f filename, I got the following message:

tail: inotify cannot be used, reverting to polling: Too many open files

Is that a potential problem?

How do I diagnose what's responsible for all the open files? I have a list of suspect processes, but if they don't turn out to be the culprits, instructions that don't rely on knowing which process to check would be useful.

  • 1
    Have you increased the number of file descriptors available via ulimit? – Ignacio Vazquez-Abrams Aug 28 '12 at 3:09
  • 2
    @IgnacioVazquez-Abrams That may be helpful to other users, but to me it'd feel like treating the symptom rather than the disease. – Andrew Grimm Aug 28 '12 at 3:13
  • While you're not wrong, sometimes apps have legitimate reasons for having many files open. – Ignacio Vazquez-Abrams Aug 28 '12 at 3:14
  • Related: Ubuntu - too many open files? – kenorb Feb 3 '19 at 0:08

You can use lsof to understand who's opening so many files. Usually it's a (web)server that opens so many files, but lsof will surely help you identify the cause.

Once you understand who's the bad guy you can

  • kill the process/stop the program
  • raise the ulimit

If output from lsof is quite huge try redirecting it to a file and then open the file

Example (you might have to Ctrl+C the first command)

lsof > ~/Desktop/lsof.log
cat ~/Desktop/lsof.log | awk '{ print $2 " " $1; }' | sort -rn | uniq -c | sort -rn | head -20
vim ~/Desktop/lsof.log
  • 44
    For the lazy: lsof | awk '{ print $2; }' | uniq -c | sort -rn | head – itsadok Nov 27 '12 at 6:10
  • 1
    I got the same error and using ulimit doesn't work. The tail -F command still returns the error. I increased the limit from 1024 to 3000 so I would imagine that I have enough room by then... I guess I'd have to reboot! – Alexis Wilke Jan 26 '13 at 11:41
  • 16
    I found itsadok's line helpful, but I think you should sort first (because uniq only works with adjacent lines), run uniq, then sort again. So lsof | awk '{ print $2; }' | sort -rn | uniq -c | sort -rn | head. – Tyler Collier Feb 2 '13 at 0:45
  • 22
    Sorting and counting up the most files open is definitely the best thing to do. Show process name as well as pid: '''lsof | awk '{ print $2 " " $1; }' | sort -rn | uniq -c | sort -rn | head -20''' – gaoithe Dec 1 '14 at 11:34
  • 2
    @gaoithe if you put that into an answer I will gladly upvote it :) – Matt Ball Jul 27 '15 at 17:56

In case anyone else needs it...

ulimit -a

Will display all current limits. Specifically ulimit -n 70000 will set the file descriptor limit.


cat /proc/sys/fs/file-max

Will display/set the kernel limit if edited.

sudo echo 200000 > /proc/sys/fs/file-max

A much more detailed explanation can be found at...

How do I increase the open files limit for a non-root user?

  • 4
    ulimits are there so you can keep tight control over resource use in your system. It is best to increase them individually for processes you know will need to use many file descriptors. By keeping them tight in testing you will find processes which might steadily leak file descriptors over time. Note also that file handles are used for any device access in unix/linux. e.g. every network socket open by a process uses a file handle. That explains why you can hit the "too many open files" in case of regular file-system files as well as any device files such as network connections. – gaoithe Dec 1 '14 at 11:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.