Today, lacking anything better to do, we’re going to learn how to change the open file limit in Linux. Why would you want to do this? Buggered if I know! But, I’m gonna tell you how! (You’re welcome!)
Actually, you could be working with many files and want to increase the number of files that can be open at one time. You might also want the opposite, as a way of limiting system resources.
Basically, in Linux, anything that can use resources has some sort of limitation. For example, there’s a limit to how many arguments that can be passed in a single command or for a new process. You’re unlikely to bump into that limit as a regular desktop Linux user, but that limit is there.
Heck, if you want to learn more about that, click this. I’m not entirely sure how to change that value, but it might actually be in some notes somewhere. Someone’s gotta know how.
Again, you’re very unlikely to run into problems as regular ol’ desktop Linux user. Realistically, you’re unlikely to have to change the open file limit in Linux. However, today is the day I tell you how! Why? ‘Cause I ain’t scared – and it’s not my computer that you’re mucking about in!
I should also mention, more to remind you gentlefolk, that everything in Linux is a file. Everything… So, you’d be surprised how many files you have open at times. Even then, you still probably don’t have too much of a need to change the open file limit.
Change The Open File Limit:
Like many articles, this one requires an open terminal. If you don’t know how to open the terminal, you can do so with your keyboard – just press CTRL + ALT + T and your default terminal should open.
With your terminal open, now is a good time to tell you that there’s a hard limit and a soft limit. The hard limit can only be changed by root and the soft limit can be altered dynamically by the process.
You can learn those limits. To find the hard limit, use this command:
And, to find the soft limit, use this command:
Those commands will output the value of your hard and soft limits, respectively.
You can obviously change those limits, else this wouldn’t be an article. To change the open file limit, you just add a new value as an additional argument. It’s something like:
And, again for the soft limit:
For example, you might increase the hard limit with a command like so:
If you want to make them permanent changes, you can do that. It’s a little different for the hard limit and the soft limit. So, to make them permanent we need to use nano to do some file editing:
And add this line:
If you want to change the soft limit, it’s a little different. It’s just:
If it’s not obvious, replace the username with your username (and no brackets, of course). Then, of course, you’ll need to save the file. To do that, just press CTRL + X, then Y, and then ENTER and that’ll save the file properly.
You shouldn’t need to reboot. The changes should be immediate and you can run the above commands to verify this. If the changes somehow didn’t take effect, reboot and you should be good to go.
I’ve never really needed to change the open file limit as a desktop Linux user, but you might have a reason to do so. If that’s the case, it makes sense to have this information handy, and now you do.
It’s yet another article in a long, long list of articles – a list that’s growing steadily! I have yet to miss a single publication date, though I feel compelled to do so – as it’d take the pressure off knowing that I no longer have a “perfect record.