Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

I was using ubuntu 12.04 ,on which I run ulimit -n ,it is showing 1024, I want to increase my open file limit from 1024 to 65535,so I tried the following command:

sudo ulimit -n 65535

but i get the following error:

sudo: ulimit: command not found

How to increase the file limit from 1024 to 65535? Any help will be appreciated.

share|improve this question

marked as duplicate by roaima, G-Man, Sparhawk, garethTheRed, Archemar Oct 25 '15 at 9:14

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Hai thare! Am seeing in my ulimit manpage adviced to use the bash builtin ulimit instead. Am not sure sudo can be used with builtins, can be it only available for external commands? – uprego Jul 5 '13 at 7:59

Limits are process-specific. ulimit is a shell bult-in and can only change limits for this shell and the processes started from this shell. sudo ulimit doesn't make any sense. Even if it won't fail it would only influence the processes started by sudo at the same time, and there aren't any.

In order to raise your limit above the hard limit you have to either raise the global hard limit for all users or set a different limit for your specific user. Those limits are defined in /etc/security/limits.conf (or /etc/security/limits.d/). Edit this file and create a new entry for your user:

sunpy             hard    nofile           65535

Save the file and open a new session. Afterwards calling ulimit -Hn inside the new session should show you the new hard limit for the number of open files. In order to use the hard limit, you have to raise your current soft limit to the hard limit by calling ulimit -n 65535.

Of course you can also change your soft limit permanently by specifying soft instead of hard in your /etc/security/limits.conf. Then you don't have to raise your soft limit manually, but the new limit will apply for each of your sessions.

Oh, and according to this answer it seems like you have to edit /etc/pam.d/common-session* and add:

session required pam_limits.so

if not already done. Otherwise those limits won't apply for your sessions.

share|improve this answer

sudo ulimit fails because ulimit is a built-in and sudo takes an executable as the first argument which it will search in PATH. sudo cd / fails for the same reason.

A workaround is to do:

sudo sh -c "ulimit -n 65535 && exec su $LOGNAME"

which sets the ulimit, and restores the original user removing the sudo privileges as expected.

Taken from http://stackoverflow.com/questions/17483723/command-not-found-when-using-sudo-ulimit

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.