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
ulimit writes the limits checked by option to standard output.
Checks a hard limit.
Checks a soft limit. Neither -H nor -S specified:
You can use options to specify the limits to be checked. You can combine the options however you want. No option specified:
Checks all limits. The other options are described under Format 2 below. |
Set limits
ulimit sets the limit defined by option to limit. You can only set one new limit per command call.
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.
Sets a soft limit. Any user can set a soft limit to a value less than the hard limit. Neither -H nor -S specified :
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:
(all) Query all limit values.
(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.
(memory) Maximum size of the data segment or heap (in Kbytes) in a process.
(number of filedescriptors) Maximum number of (open) file descriptors permitted in a process plus 1.
(time) Maximum CPU time (in seconds) permitted for a process. No option specified:
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
You have tried to increase the currently set file size limit. This privilege is reserved for POSIX administrators only. |
Exit status
0 | If the command is executed successfully |
>0 | Rejection 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.
|
Example 2
You want to check and then reduce the maximum file size. This limit can only be increased again by the POSIX administrator.
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] |