How to fix file size limit exceeded

Linux provides you with options to limit hardware resources as per users and groups to manage optimal performance all around users, and it is common to find limitations in shared hosting to prevent heavy usage by other tenants.

In almost every shared hosting situation, you will see the resources available to the account (bandwidth, disk space, CPU power) getting capped off by an application that was installed on the account.

A similar kind of incident happened to me a few days back when I was downloading the AlmaLinux 8.6 DVD release using the wget command. All of a sudden, files got stopped, and when I checked the reason for stopping, I found “File size limit exceeded.” Then I remembered I had added a limit for file sizes that should not exceed more than 4GB to save some space on my 250 GB SSD.

If your system also has a file size limit that you want to remove or want to extend, then this article is enough for you.

If you want to know more about ulimit, refer to this article: ulimit command usage in Linux

Check maximum file size limit using ulimit

As you know, ulimit has two kinds of limits: soft limit and hard limit, so to fix the file size limit, first, we should know what the limits have been applied to your machine:

For general reference, the soft limit value is always less than the hard limit, and the hard limit value can only be modified by the root user or sudo user. 

Normal users can change the soft limit, but they are not allowed to extend the soft limit more than the specified hard limit.

To check the limit, you can use the following code:

Soft limit

If you want to find the limit for all the resources you can use, -Sa options. But if you just want information about file size, then use -Sf:

$ ulimit -Sa
$ ulimit -Sf
Show hard limit of file size
Show hard limit of file size
-S soft limit -a: all resource options -f: file option

Hard limit

To check the hard limit of all resources, you can use -Ha, or if you just want to know the limit of file size, then use –Hf:

$ ulimit -Ha
$ ulimit -Hf
Show hard limit of file size
Show hard limit of file size
-H: hard limit -a: all resource options -f: file option

From the above screen capture, you can find that my system has a soft limit of 4096MB, which means around 4GB. Oh, I see now. That’s the reason files get stopped downloading when the threshold hold limit gets hit.

And if you have noticed the hard limit output, you will find that there is no restriction on it. This means I can easily change the soft limit to any number, or I can simply remove it.

If the hard limit was set, then you need to be a root user or sudo user to change the value. Don’t get disappointed; we have another article in which we will guide you on how to be a superuser. Please refer to this link to be a superuser. If you are already a super user, then you just need to modify the file present in /etc/security/limit.conf.

Change the soft limit of file size from terminal

As you know, I have set the soft limit for file size, but now I want to extend the file size limit to 15 GB. So to extend it further, paste the following command into your terminal and make sure to multiply the size to 1024. For example, 15 * 1024 = 15360

$ ulimit -Sf 15360

If you don’t want to set any limit on file size, then use unlimited.

$ ulimit -Sf unlimited 

You can set any arbitrary file size unless and until you don’t exceed the specified hard limit by your administrator or sudo users in limit.conf.

One disadvantage of setting a soft limit from the terminal is that the changes will not persist once you close the shell or terminal window.

To make them persistent, you need to modify the limit.conf file.

Change soft and hard limits of file size from /etc/security/limit.conf

Before making any changes to /etc/security/limit.conf I advise you to make a backup. If anything goes wrong, you can easily replace it with a backup.

Open your terminal window and paste the following command into it and enter the sudo password.

$ sudo cp /etc/security/limits.conf /etc/security/limits.bak

Once you have created a backup, you can modify the file.

$ sudo nano /etc/security/limit.conf

First, scroll down and go to the very bottom, and specify the details in the specified format.

  • <domain>: Define username and group. It supports wildcard characters (* or %). use “@group” or “%group”.
  • <type>: specify the type of limits hard or soft
  • <item>: on which resource item do you want to set a limit
  • <value>: set value

To explain you more clearly, I’ll apply the hard limit to the file size on user “trendoceans“, select the type “hard”, and choose “fsize” as an item or resource that can never exceed a file size of 20GB. If he wants to surpass the limit, then he needs to modify the limit.conf file.

trendoceans      hard   fsize            20480    
Modify file size hard limit
Modify file size hard limit

If you ever want to disable the rule, just append “#” to a specified user or group, and if you think you should remove the limit then, simply delete the line.

One important point is to never set a file hard limit of less than 1 GB or less. Otherwise, your system will behave weirdly and the application will crash.

After making changes please reboot your system to implement changes, and run the ulimit -HF command to verify changes.

$ ulimit -Hf
File size limit changed
The file size limit has changed to 20480

As you can see now, the file size has been changed from unlimited to 20480, and if you try to surpass the hard limit using the soft limit, you will not be able to modify it and an error will print on your screen “bash: ulimit: file size: cannot modify limit: Invalid argument”.

$ ulimit -Sf 22000
Try to update soft limit
Try to update the soft limit

Wrap up

That’s all for now!

if you have any queries or if I missed something, please do let me know in the comment section.

0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments