在 Ubuntu Server 中嘗試 sudo source /etc/profile 或 sudo ulimit -n 65535 時出現 command not found,原因是 source 和 ulimit 是 Shell 內建指令,非獨立可執行檔,sudo 啟動的非互動式 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 command會在新的非登入、非互動 Shell 中執行command,該 Shell 不讀取.bashrc/.profile,也不提供source、ulimit、cd等內建指令。sudo -s或sudo -i則啟動登入 Shell,完整載入環境與內建命令。