On Unix-like operating systems, ulimit is a builtin command of the Bash shell. It displays or sets resource limits of the shell.

Description

Resources that can be limited include the size of files written, allocated memory, and how many files may be open at once.

  • Description
  • Syntax
  • Examples
  • Related commands
  • Bash builtins help
  • Linux commands help

The average user on a laptop or desktop Linux computer may never need to alter their default resource limits. However, if you are operating a server with many high-performance processes, or a high number of simultaneous users, limiting resources may be necessary. By limiting resources, you can prevent any single process or user session from slowing down or interfering with the rest of the system.

Syntax

ulimit [-S] [-H] [-a] [-b] [-c] [-d] [-e] [-f] [-i] [-k] [-l] [-m] [-n] [-p] [-q] [-r] [-s] [-t] [-u] [-v] [-x] [-P] [-T] limit

Some options allow you to specify a new limit. This can be an appropriate numeric value, or the special values soft, hard, or unlimited.

On Linux systems that use the systemd or upstart initialization systems, ulimit settings might be ignored. On these systems, use prlimit instead.

  • The value soft refers to the “soft” resource limit. This is a limit which may be exceeded if necessary for short periods of time, but never exceed the hard limit.
  • The value hard refers to the “hard” resource limit. The hard resource limit may never be exceeded under any circumstances.
  • The value unlimited means that there are no limitations on that resource.

If you include the -S or -H option, all other options will refer to the soft or hard limit, respectively. If you specify neither or both options, -S is assumed.

Some options, but not all, will report the current limit if you omit the limit option.

Options

The ulimit builtin command takes the following options.

Exit status

The ulimit command returns 0 for success, and 1 if anything goes wrong, such as invalid options or a permissions error.

The options available to ulimit are system dependent. Run “help ulimit” to check which options are available on your system.

Examples

ulimit

Report the soft limit on file size.

ulimit -f

Same as the above command.

ulimit -Hf

Report the hard limit on file size.

ulimit -H

ulimit -a

Report all soft resource limits.

ulimit -Sa

ulimit -Ha

Report all hard resource limits.

ulimit -u

Report the soft limit on number of user processes.

ulimit -u 8000

Set the soft limit on number of user processes to 8000.

vimdiff <(ulimit -Sa) <(ulimit -Ha)

Use vimdiff to compare soft limits and hard limits. The less than symbol with parentheses <( … ) is an example of bash process substitution. The ulimit commands are run in subshells, and the output of each command is read by vimdiff as if from files. The soft limits are shown on the left and hard limits on the right, as in the screenshot below.

df — View used and available disk space.free — View used and available memory.