Linux increase the maximum number of open files or file descriptors

Q. How do I increase the maximum number of open files under CentOS Linux? How do I open more file descriptors under Linux?

A. ulimit command provides control over the resources available to the shell and to processes started by it, on systems that allow such control. The maximum number of open file descriptors displayed with following command (login as the root user).

Command to list umber of open file descriptors

Use the following command command to display maximum number of open file descriptors:
cat /proc/sys/fs/file-max
Output:

75000

75000 files normal user can have open in single login session.

The number of maximum files was reached, how do I fix this problem?

Many application such as Oracle database server needs this range quite higher. So you can increase the maximum number of open files by setting new value in kernel variable /proc/sys/fs/file-max as follows (login as the root):
# sysctl -w fs.file-max=100000
Above command forces the limit to 100000 files. You need to edit /etc/sysctl.conf file and put following line so that after reboot the setting will remain as it is:
# vi /etc/sysctl.conf
Append a config directive as follows:
fs.file-max = 100000
Save and close the file. Users need to log out and log back in again to changes take effect or just type command:
# sysctl -p
Verify your settings with command:
# cat /proc/sys/fs/file-max
OR
# sysctl fs.file-max

Updated for accuracy.

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 11 comments… read them below or add one }

1 Tachyon 10.21.06 at 2:35 am

Icreasing the file handles is a good tip, but 5000 is very low these days. 200000 is more realistic for any modern system.
Also, there’s no need to logout, just edit the /etc/sysctl.conf and then type ’sysctl -p’ as root.

Thanks,
Tachyon

2 Maroon Ibrahim 06.23.07 at 12:25 pm

Does this command work for Debian and does it affect SQUID file descriptor too?
Best Regards?

3 vivek 08.15.07 at 6:07 pm

Maroon,

Yes it works on Debian and all other Linux systems/distros.

4 Sathish A 08.28.07 at 11:40 pm

how to increase in a Redhat linux server? How to find the location of sysctl.conf file or how to find in which file the limit has been set?

thanks in advance

5 baka.tom 09.11.07 at 11:34 pm

i tried this on a CentOS (which by the way, i’ve decided the worst linux distribution ever), and it doesn’t seem to work. ulimit -n still says 1024, even after logout, even after reboot.

6 bourne 09.13.07 at 2:10 pm

/etc/sysctl.conf is good for the system-wide amount, but don’t forget that users also need different limits. See /etc/security/limits.conf (Debian, Redhat, SuSE all have it, probably most others as well) to assign specific limits on per-group, per-user, and default basises.

7 jason 09.13.07 at 8:55 pm

I am running “Red Hat Enterprise Linux ES release 4 (Nahant Update 5)” and followed the instructions above. Like “baka.tom”, I was unable to see the change reflected by typing “ulimit -n”. I don’t know if this is a problem, but it certainly reduces the credibility of this article (unless I screwed up, of course).

8 vivek 09.14.07 at 4:32 am

baka.tom / jason,

The FAQ has been updated for latest kernel. It should work now. Let me know if you have any more problems.

bourne, thanks for pointing out user level or group level filelimit option.

I appreciate all feedback.

9 jackson 12.01.07 at 1:54 am

Red Hat configuration requires the following line to be added for /etc/security/limits to work.

in /etc/pam.d/login
session required pam_limits.so

10 Arstan 04.23.08 at 2:23 am

I’m trying to make 8192 on Ubuntu 7.10, adding

* soft nofile 8192
* hard nofile 8192

doesn’t work, but when i do change * to username(lets say root) it applies.

So how to change it system wide?

11 shankar 06.19.09 at 3:58 pm

you could use the following command to check if the given change reflected

#ulimit -n -H

that gives the hard value…

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Tagged as: , , , , , , ,

Previous post: Access Linux from Windows XP system

Next post: Boot Linux Grub Into Single User Mode