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
Non-linear Components
In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co
11 min read
Spring Boot Tutorial
Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance
10 min read
Class Diagram | Unified Modeling Language (UML)
A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact
12 min read
Steady State Response
In this article, we are going to discuss the steady-state response. We will see what is steady state response in Time domain analysis. We will then discuss some of the standard test signals used in finding the response of a response. We also discuss the first-order response for different signals. We
9 min read
Backpropagation in Neural Network
Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and
9 min read
Polymorphism in Java
Polymorphism in Java is one of the core concepts in object-oriented programming (OOP) that allows objects to behave differently based on their specific class type. The word polymorphism means having many forms, and it comes from the Greek words poly (many) and morph (forms), this means one entity ca
7 min read
3-Phase Inverter
An inverter is a fundamental electrical device designed primarily for the conversion of direct current into alternating current . This versatile device , also known as a variable frequency drive , plays a vital role in a wide range of applications , including variable frequency drives and high power
13 min read
What is Vacuum Circuit Breaker?
A vacuum circuit breaker is a type of breaker that utilizes a vacuum as the medium to extinguish electrical arcs. Within this circuit breaker, there is a vacuum interrupter that houses the stationary and mobile contacts in a permanently sealed enclosure. When the contacts are separated in a high vac
13 min read
AVL Tree Data Structure
An AVL tree defined as a self-balancing Binary Search Tree (BST) where the difference between heights of left and right subtrees for any node cannot be more than one. The absolute difference between the heights of the left subtree and the right subtree for any node is known as the balance factor of
4 min read
Linux Commands Cheat Sheet
Linux, often associated with being a complex operating system primarily used by developers, may not necessarily fit that description entirely. While it can initially appear challenging for beginners, once you immerse yourself in the Linux world, you may find it difficult to return to your previous W
13 min read