Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

ulimit - set or report file size limit

&pagelevel(4)&pagelevel

The POSIX shell built-in ulimit enables you to

  • check the file size limits imposed for the current shell and its child processes

  • set or change the individual file size limits for the current shell and all its child processes.
    Normal users without POSIX administrator privileges may decrease this limit, but not increase it. The new limits apply to files written by the current shell and all its child processes.

    You cannot increase a limit that has been decreased until you have terminated the shell in which you have decreased the limit.


Syntax


Format 1:ulimit[ -H][ -S][ option]
Format 2:ulimit[ -H][ -S][ option] limit
Check limits
Format 1:ulimit[ -H][ -S][ option]


ulimit writes the limits checked by option to standard output.

-H

Checks a hard limit.

-S

Checks a soft limit.

Neither -H nor -S specified:
ulimit writes the soft limits to standard output.

option

You can use options to specify the limits to be checked. You can combine the options however you want.

No option specified:
ulimit uses the -f option (see Format 2 below).

-a

Checks all limits.

The other options are described under Format 2 below.

Set limits
Format 2:ulimit[ -H][ -S][ option] limit


ulimit sets the limit defined by option to limit. You can only set one new limit per command call.

-H

Sets a hard limit. Normal users without POSIX administrator privileges may reduce any hard limit. However, only the POSIX administrator may increase a hard limit.

-S

Sets a soft limit. Any user can set a soft limit to a value less than the hard limit.

Neither -H nor -S specified :
ulimit sets hard and soft limits to the specified value.

option

You can use options to specify the limits to be set. The following limits, described in more detail under getrlimit() [4], are available for your current shell and all its child processes:

-a

(all)

Query all limit values.

-f

(file size)

Maximum file size (in 512-byte blocks) that you may create (write); there is no limit on reading. If file size is 0, no files can be created. If you exceed the default value, you either receive an error message from the appropriate command (depending on the command you have used to create the file) or the new file only contains as much data as the imposed limit can accommodate.

Example for file size

After the command ls -lR >file, file will contain as many bytes as are permitted by the current size limit.
The command cp, on the other hand, will issue an error message if the file to be copied exceeds the currently set file size limit.

-m

(memory)

Maximum size of the data segment or heap (in Kbytes) in a process.

-n

(number of filedescriptors)

Maximum number of (open) file descriptors permitted in a process plus 1.

-t

(time)

Maximum CPU time (in seconds) permitted for a process.

No option specified:
ulimit uses the -f option.

limit

Sets the size limit for the current shell and all its child processes in accordance with the specified option. Normal users without POSIX administrator privileges may only specify values less than the current size limit defined for limit. As a POSIX administrator, however, you may also increase this limit with limit. If you specify the string unlimited for limit, the limit is set to the maximum possible value.

Error

sh: ulimit; exceeds allowable limit

You have tried to increase the currently set file size limit. This privilege is reserved for POSIX administrators only.

Exit status

0If the command is executed successfully
>0Rejection of higher limit or error

Locale

The following environment variables affect the execution of ulimit:

LANG

Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined.

LC_ALL

If set to a non-empty string value, override the values of all the other internationalization variables.

LC_CTYPE

Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files), the classification of characters as upper- to lower-case, and the mapping of characters from one case to the other.

LC_MESSAGES

Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.

NLSPATH

Determine the location of message catalogs for the processing of LC_MESSAGES.

Example 1

The current soft limit value for the maximum number of file descriptors is increased. All users may do this provided that the new limit value remains below the hard limit value. The new limit value is also valid in a subshell.

$ ulimit -Sn 80
$ ulimit -Sn

80

Example 2

You want to check and then reduce the maximum file size. This limit can only be increased again by the POSIX administrator.

$ ulimit
unlimited

$ ulimit 20000

$ sh
$ ulimit

20000

The new limit is also valid in subshells. From now on, only files smaller than 20,000 * 512 bytes can be created.

See also

getrlimit(), signal(), ulimit() [4]