increase open file in linux

How to Increase Open File Limit in Linux

Every operating system, including Linux, has a maximum limit on number of open files. It is sufficiently large and it is unlikely that you will ever hit this limit by regular usage. But sometimes if any application or process on your system has opened too many files, then you may get an error “Too many open files” and be unable to open any more files or run any new processes. In this article, we will learn how to increase open file limit in Linux.


How to Increase Open File Limit in Linux

We will learn how to increase open file limit in Linux by first checking the current limit of open files and file descriptors. For this purpose, you need root access to your system, or login as a user with sudo privileges.


Find Open File Limit

The maximum number of open files allowed is stored in /proc/sys/fs/file-max. You can view it using the following command.

$ cat /proc/sys/fs/file-max
818354

The above output shows the number of open files and file descriptors you can have on your system.

You can also check system resource limits using ulimit command. There are two types of system limits – soft limit and hard limit. Soft limits can be modified dynamically while hard limits can be changed only by root user.

Here is the command to check hard limits.

# ulimit -Hn
4096

Here is the command to check soft limit.

# ulimit -Sn

1024

If you want to check hard and soft limit for another user test_user, use su command to switch user first, and then run ulimit command.

# su test_user
$ ulimit -Sn

1024


Check System Wide File Descriptors Limit in Linux

Some applications like databases and web servers require more open files. You can increase limit of opened files in Linux by editing kernel directive fs.file-max. Use sysctl utility for this purpose. Here is an example to increase open file limit to 500000.

# sysctl -w fs.file-max=500000

But please note, the above changes will remain only until next system reboot. If you want to make these changes permanent, then you need to edit sysctl.conf.

# vi /etc/sysctl.conf

Add the following line.

fs.file-max=500000

Save and close the file. You need to logout and login again to apply changes. If you want to apply changes without logging out, you can run the following command.

# sysctl -p


Set User Level Open File Limits in Linux

In above examples, we have set global file limits in Linux. You can also set user-specific file limits in Linux by editing /etc/security/limits.conf.

# vi /etc/security/limits.conf

It consists of a bunch of lines, each defining system limit for different users. Its format is

<domain>  <type>  <item>  <value>

Here is an example to set soft and hard limits for user test_user.

## Example hard limit for max opened files
test_user        hard nofile 4096
## Example soft limit for max opened files
test_user        soft nofile 1024

In this article, we have learnt how to increase open files in Linux using sysctl.conf and limits.conf. You can use the different methods described above, to increase open files for all user or specific users,

Also read:

How to Count Total Lines of Code in Directory Recursively
How to Fix Yum Error: Database Disk Image is Malformed
How to Fix “Failed to Mount /etc/fstab” Error in Linux
How to Compress Images in Linux
How to Reduce PDF Size in Linux

Leave a Reply

Your email address will not be published. Required fields are marked *