Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> 關於 Linux

Ubuntu sudo 執行 source/ulimit 報「command not found」解決方案

編輯:關於 Linux

在 Ubuntu Server 中嘗試 sudo source /etc/profile 或 sudo ulimit -n 65535 時出現 command not found,原因是 source 和 ulimit 是 Shell 內建指令,非獨立可執行檔,sudo 啟動的非互動式 Shell 不載入這些內建命令。

正確做法:取得 root Shell 再執行內建指令

sudo -s
# source /etc/profile
# ulimit -n 65535

完整流程示範

$ ulimit -n
1024
$ sudo sh -c 'echo "ulimit -SHn 65535" >> /etc/profile'
$ sudo -s
# source /etc/profile
# ulimit -n
65535

sudo 內建指令錯誤

原理解析: sudo command 會在新的非登入、非互動 Shell 中執行 command,該 Shell 不讀取 .bashrc/.profile,也不提供 source、ulimit、cd 等內建指令。sudo -s 或 sudo -i 則啟動登入 Shell,完整載入環境與內建命令。
Copyright © Windows教程網 All Rights Reserved