sudo: ulimit: command not found

在這看到的:http://stackoverflow.com/questions/17483723/command-not-found-when-using-sudo-ulimit


修改系統文件打開數,具體修改方法就不寫了,但是在普通用戶使用sudo執行的時候報錯:

130> sudo ulimit
sudo: ulimit: command not found

本來以爲ulimit沒在path變量中,用絕對路徑就行了:
1> which ulimit
/usr/bin/which: no ulimit in (/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin)

查了下原因ulimit不是一個單獨的程序。sudo會去找二進制文件運行。由於找不到ulimit的二進制可執行文件,故報錯。 類似的命令還有:cd

可以這樣設置:
sudo sh -c "ulimit -n 65535 && exec su $LOGNAME"

該命令創建一個新的shell,然後設置ulimit,同時將用戶切換至當前用戶,當命令退出時,不會是以root權限退出。

英語解釋:
ulimit is a shell builtin like cd, not a separate program. sudo looks for a binary to run, but there is no ulimit binary, which is why you get the error message. You need to run it in a shell.
However, while you do need to be root to raise the limit to 65535, you probably don’t want to run your program as root. So after you raise the limit you should switch back to the current user.
To do this, run:
sudo sh -c "ulimit -n 65535 && exec su $LOGNAME"
and you will get a new shell, without root privileges, but with the raised limit. The exec causes the new shell to replace the process with sudo privileges, so after you exit that shell, you won’t accidentally end up as root again.



你將得到一個新的shell,沒有root權限,但是提高了限制。 exec使新shell以sudo權限替換進程,所以在你退出shell之後,你不會意外地以root身份結束
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章