終端機啟動圖形介面或長時間任務預設佔據前台,關閉視窗即終止進程。掌握背景執行與 nohup 讓工作脫離終端機生命週期。
firefox -search "linux.cn" # 前台執行,終端機被佔用
libreoffice & # 末尾加 & 符號 → 背景執行,立即回到提示符
帶參數時 & 必須放最後。
nohup command [arg...] &
關閉終端機後進程仍持續運行,輸出導向 nohup.out。
/path/to/yourprogram &
find / -name firefox 2>/dev/null | less
sudo find / -name firefox | more
# 當前目錄遞迴搜尋
find . -name firefox
sudo !!
若權限不足導致失敗,直接輸入此指令自動補上 sudo 重跑。