Session and utilities
The ulimit command
Shows or sets the resource limits of the shell and the programs it starts.
Most useful options
-aShows all current limits.-nMaximum number of files open at once. Without a value, it shows the soft limit.-uMaximum number of processes your user can have.-fMaximum size of the files the shell and its children write. It is the option used when you give none.-cMaximum size of the core files written when a program crashes.-sMaximum stack size of each process, in kilobytes.-SChanges only the soft limit, the one in force now. It can be raised up to the hard limit.-HChanges only the hard limit. Once lowered, a user without root cannot raise it again.Copy-ready examples
$ ulimit -asee all the limits of the current session.$ ulimit -nhow many files the shell can have open at once, with the soft limit.$ ulimit -Hnthe hard limit on open files, the ceiling you cannot exceed without root.$ ulimit -Sn 2048changes only the soft limit of the shell. The hard limit does not change.$ (ulimit -n 4096 && ./mi-programa)raises the limit only for that program, inside a subshell, without touching the current shell.You can try them in the browser terminal: it does not touch your computer.
Common errors
| Message | Cause | Fix |
|---|---|---|
| bash: ulimit: open files: cannot modify limit: Operation not permitted | You asked for a value above the hard limit, which you cannot exceed without root. | Check the ceiling with ulimit -Hn and ask for a lower value, or ask an administrator to raise it. |
| bash: ulimit: -Q: invalid option | ulimit has no option with that letter. | Check the valid letters with help ulimit and use one of them. |
| bash: ulimit: abc: invalid number | The value you passed is neither a number nor a recognized word such as unlimited. | Write an integer, or unlimited if you want to remove the limit. |
Typical mistakes
- Changes affect the shell where you make them and what it launches afterwards. Another open terminal is not changed.
- Without -S or -H, setting a value changes both limits. Lowering the hard limit that way cannot be undone without root in that shell: use -S for a temporary adjustment.
- Without options, ulimit shows the file size limit (-f), not the open files limit. For open files use -n.
Differences from similar commands
prlimit: queries or changes the limits of a process already running, by its PID. ulimit only affects the current shell and what it launches from there.- nice: changes how much CPU priority a program gets, not its memory or file limits.
FAQ
Why does it show the file size limit when I give no options?
Because bash assumes -f when you give no option. To see open files, write ulimit -n.
Do the changes survive a reboot?
No: ulimit only changes the current shell. Fixed limits for a service are set when it starts, not with ulimit.
Why can I not raise a limit?
Because you already lowered the hard limit or you are above it. Without root the hard limit cannot be raised; ask an administrator.
Learn to actually use it
The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.
Start the free course