Tips

Let’s Learn How To Change The Open File Limit In Linux

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:

ulimit -Hn

And, to find the soft limit, use this command:

ulimit -Sn

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:

sudo ulimit -Hn <new_value>

And, again for the soft limit:

sudo ulimit -Sn <new_value>

For example, you might increase the hard limit with a command like so:

sudo ulimit -Hn 10000

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:

sudo nano /etc/security/limits.conf

And add this line:

hard nofile <new_limit>

If you want to change the soft limit, it’s a little different. It’s just:

<username> soft nofile <new_limit>

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.

Closure:

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.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

KGIII

Retired mathematician, residing in the mountains of Maine. I may be old and wise, but I am not infallible. Please point out any errors. And, as always, thanks again for reading.

Recent Posts

Enable/Disable Your Network Interface

Today we'll cover one way to enable or disable your network interface in the Linux…

5 months ago

Check Your NIC Speed In The Terminal

Today's exercise is a nice and simple exercise where we check your NIC speed in…

5 months ago

Easily Monitor Your Wireless Connection

Have you ever wanted to easily monitor your wireless connection? Well, now you can learn…

6 months ago

Count The Files In A Directory

I think I've covered this before with the ls command but this time we'll count…

6 months ago

Get System Information With The ‘uname’ Command In Linux

Today we'll be learning about a basic Linux command that's known as 'uname' and it…

6 months ago

hardinfo Has Been Rebooted As hardinfo2

If you've used hardinfo in the past, it may interest you to know that hardinfo…

6 months ago