How to Change the Number of Open File Limit in Linux?
Last Updated :
09 Apr, 2021
If you are an active Linux user, who has to work with many files on Linux at a time then you might have definitely faced a problem regarding “Too many open files” on a Linux system. When you have reached the maximum open file limit you will get an error message displaying "Too many open files (24)” error on your screen.
Why do we face such a thing? Well, Linux operating system set a limit of "open files" that a user can open at a time, Linux operating system uses this way to restrict the user from opening too many files at a time.
But luckily we can modify the number of Open File Limits in Linux according to our wish using some different methods that we are going to discuss today in this article.
Types of open file Limit
Why does Linux Limit the number of opened files? The reason is first due to security purpose so that no software creates files endlessly till the Linux server crashes and also that the Linux Operating System needs memory to manage each open file and memory is kind of limited especially on embedded systems so there is some limitation for a number of open files in a system by a user.
There are 2 types of open file Limit, are as follows:
- Hard Values of File Descriptors.
- Soft Values of File Descriptors.
Hard Values of File Descriptors: Hard value limits are those file limits that can only be modified by the root user. Non-root users cannot change the value of a hard limit.
We can check the hard value limit using the following command:-
$ ulimit -Hn
Soft Values of File Descriptors: A soft value limits are those limit that shows the current effective value for the user that can be modified by a user process at any time. Core dumps can be disabled by soft values.
We can check the soft value limit using the following command:-
$ ulimit -Sn

Methods to Change the Number of Open File Limit in Linux
ulimit is a bash built-in shell command(so you might not get the desirable result from it on other types of shell) which can be used to increase the number of open files descriptors limit for each process in Linux shell.
Syntax : ulimit [options [limit]]
a.) -a (Current Settings Passing):- argument that causes ulimit to display its current settings
To show the current limitation use the following command:
ulimit -a | grep open
b.) -f (File Limits): argument limits the size of files that may be created by the shell.
c.) -H and -S (Hard and Soft Limits) is already discussed above
Now For editing the Limit use the following command:-
ulimit -n 3000
But this value will be reset if you restart your computer or logout the user.
For changing the value permanently we have to edit one of the user’s configuration files (.bashrc or .profile) or the system-wide configuration files (/etc/bashrc or /etc/profile) by adding the following command at the end of the file:-
# vim .bash_profile
ulimit -n 3000
Now the changes are permanent, even you restart your computer, it won't change.
Another best way to modify the open file limit is done through this PAM module called pam_limits. We have to configure it by editing the /etc/security/limits.conf file.
There are 4 essential fields present in this configuration file. They are:-
- domain: Domain describes a specific unit to which the limit applies that can be a username, a group name (with the form @groupname syntax), or an asterisk ( * ) wildcard (wildcard limits are not applied to root).
- type: Type specifies whether the limit is hard or soft.
- item: it specifies the type of item that is being limited. This could be core (limits the size of core files), fsize (maximum file size), data (maximum data size), sizeetc.
- value: values that will be applied to the limit.

Now you can edit this configuration file to change the limit of opened files for all users, For instance, you can add the following lines below the end of the file lines:
# vim /etc/security/limits.conf
* hard nofile 21000
* soft nofile 16000
Now edit the file /etc/pam.d/login
# vim /etc/pam.d/login
session required pam_limits.so
And you are done changing the open file limit.
Similar Reads
How to List Open Files in Linux | lsof Command
In the world of Linux, understanding and managing open files is crucial for system administrators and users alike. The Linux operating system provides a powerful utility called lsof (List Open Files) that allows users to gain insights into the files currently open on their system. In this article, w
7 min read
How to Open a File in Linuxâ
In Linux, a file is a fundamental unit of storage, representing everything from documents and images to system logs and program data. Unlike traditional operating systems, Linux treats almost everythingâfiles, directories, devices, and processesâas a file. Whether you're accessing a simple text docu
6 min read
How to Rename File in Linux | rename Command
Changing the names of files in Linux is something we often do, and the "rename" command is like a helpful friend for this job. This guide is like a journey to becoming really good at renaming files on Linux, showing you how handy and useful the "rename" command can be. Whether you're just starting o
8 min read
How to Fix the âNo space left on deviceâ Error in Linux
When you try to save files or write data on a Linux system, you might get the "No Space Left on Device" error. This error means that the storage space you are trying to use is full and does not have enough room left for your operation. To fix this error, you can either make more space available in t
7 min read
How to change the default SSH port in Linux
SSH (Secure Shell) is a network protocol used to securely connect to the remote server where the data between the server and client is transferred in an encrypted format. In the world of Linux system administration and security, one essential practice is changing the default SSH port. This article w
7 min read
How to Edit Text Files in Linux: Proven 3 Methods
Need to tweak a file in Linux but not sure where to start? Editing text files in Linux is a handy skill that can help you fix settings, write scripts, or just note down notes all from your keyboard. This blog is here to help you get started, even if youâre new to Linux. Weâll show you simple ways to
4 min read
How to Fix the "Too Many Open Files" Error in Linux
Encountering the "Too Many Open Files" error in Linux can be frustrating, especially when it disrupts your workflow or server operations. This error typically occurs when a process or system reaches its limit for open file descriptors, which are references to open files or resources such as sockets,
5 min read
How to Set Nginx Max Open Files in Linux
In Linux, the Nginx depends on the system limits for maximum open files to efficiently handle the parallel connections and to serve the web content. The maximum open file limit determines the number of files, which includes the sockets, that Nginx can simultaneously have opened. We can adjust this l
4 min read
How to change the maximum upload file size in PHP ?
The maximum size of any file that can be uploaded on a website written in PHP is determined by the values of max_size that can be posted or uploaded, mentioned in the php.ini file of the server. In case of hosted server need to contact the administrator of the hosting server but XAMPP has interprete
2 min read
How to Change FTP Port in Linux?
Files are either uploaded or downloaded to the FTP server. The files are moved from a personal computer to the server when you upload files. The files are moved from the cloud to your personal computer when the files are downloaded. In order to transfer files through FTP, TCP/IP (Transmission Contro
1 min read