一、通用基礎指令
date:顯示/設定系統日期時間
stty -a:查看控制字元(Ctrl-C, Ctrl-D, Ctrl-Z 等)
passwd:變更密碼(passwd -h 查說明)
logout, login:登出/登入 Shell
pwd:顯示目前工作目錄
more, less, head, tail:檢視檔案內容(分頁/頭尾)
lp/lpstat/cancel, lpr/lpq/lprm:列印管理
chmod u+x ...:修改檔案權限
rm -fr dir:刪除非空目錄
cp -R dir:複製目錄
fg jobid:前景執行背景工作;Ctrl-Z 暫停前景工作,bg jobid 轉背景;job & 直接背景執行
kill -9 PID:發送 SIGKILL 強制終止程序(man kill 查所有訊號)
ps -e 或 ps -o pid,ppid,session,tpgid,comm:進程檢視
二、Ubuntu/Debian 套件管理
dpkg(底層工具)
- 安裝:
dpkg -i package.deb
- 移除:
dpkg -r package;連同設定檔:dpkg -P package
- 查詢安裝內容:
dpkg -L package
- 查詢檔案屬於哪個套件:
dpkg -S filename
- 前端工具:
dselect, aptitude
apt/apt-get(高層工具)
- 安裝:
apt-get install pkg
- 更新套件清單:
apt-get update
- 升級系統:
apt-get upgrade;智慧升級(處理依賴變動):apt-get dist-upgrade
- 修復損壞依賴:
apt-get -f install
- 移除無用套件:
apt-get autoremove
- 移除套件:
apt-get remove pkg;連設定檔:apt-get remove pkg --purge
- 清理已移除套件殘留設定檔:
dpkg -l | grep ^rc | awk '{print $2}' | xargs dpkg -P
- 快取目錄:
/var/cache/apt/archives;清理:apt-get clean / apt-get autoclean
- 查詢依賴:
apt-cache depends pkg;反向依賴:apt-cache rdepends pkg
- 搜尋套件:
apt-cache search keyword
- 檢視套件說明:
apt-cache show pkg
- 下載原始碼:
apt-get source pkg(需啟用 deb-src 源)
- 安裝建置依賴:
apt-get build-dep pkg
- 加入安裝光碟源:
apt-cdrom add
三、系統資訊與管理
- 核心版本:
uname -a
- Ubuntu 版本:
cat /etc/issue
- 網卡狀態:
ethtool eth0
- 記憶體/CPU 資訊:
cat /proc/meminfo, cat /proc/cpuinfo
- 磁碟空間:
df -h
- 分區表:
fdisk -l
- 檔案/目錄大小:
du -h file, du -hs dir(目錄總計), du -h dir(各檔案)
- 記憶體使用:
free -m (MB), -g (GB), -k (KB)
- 進程列表:
ps -e 或 ps -aux
- 終止進程:
kill PID;強制終止所有同名進程:killall -9 name
四、網路設定與診斷
- ADSL 設定:
sudo pppoeconf
- 手動撥號:
sudo pon dsl-provider
- 開機自動撥號:
sudo /etc/ppp/pppoe_on_boot
- 斷線:
sudo poff
- IP 對應 MAC:
arping IP
- 查看網路介面:
ifconfig 或 ifconfig eth0
- 路由表:
netstat -r
- 啟用/停用網卡:
sudo ifconfig eth0 up/down
- 服務管理:
update-rc.d service defaults 99 (加入開機), update-rc.d service remove (移除), /etc/init.d/service restart/stop/start (臨時控制)
- 主控台顯示中文:
sudo apt-get install zhcon
- 尋找檔案:
whereis file 或 find /path -name file
- SSH 傳檔:
上傳:scp -rp /local/path user@remote:/remote/path
下載:scp -rp user@remote:/remote/path /local/path
五、壓縮與解壓縮
.tar.gz:解壓 tar zxvf file.tar.gz;打包 tar zcvf out.tar.gz dir1 dir2
.tar.bz2:解壓 tar jxvf file.tar.bz2;打包 tar jcvf out.tar.bz2 dir1 dir2
六、Nautilus 檔案總管特殊 URI 與熱鍵
| URI | 功能 |
computer:/// | 所有掛載裝置與網路 |
network:/// | 瀏覽可用網路 |
burn:/// | 燒錄資料虛擬目錄 |
smb:/// | Windows/Samba 網路資源 |
file:/// | 本地檔案 |
trash:/// | 回收站 |
ftp://, ssh:// | FTP/SSH 遠端目錄 |
fonts:/// | 字型資料夾(拖入安裝) |
themes:/// | 系統主題資料夾 |
熱鍵:Ctrl+H 顯示隱藏檔,Ctrl+L 顯示地址列,fonts:/// 查看已安裝字型。
七、補充實用技巧
- 監聽埠:
netstat -tupln (tcp, udp, program, listen, numeric)
- 關鍵字搜尋指令:
man -k keyword 或 apropos keyword
- 實際磁碟佔用:
du;字元/字/列計數:wc -c/-l/-w
- 檔案位元流檢視:
od -t x1 file (十六進位), od -t c file (ASCII)
- 指令路徑:
which cmd;套件歸屬:dpkg -S $(which cmd);套件完整內容:dpkg -L pkg
- 查看所有 man page 區段:
man -a cmd (q 離開, 下一區段)
八、Bash 高效編輯熱鍵
| 熱鍵 | 動作 |
| Ctrl+A | 游標移至行首 |
| Ctrl+E | 游標移至行尾 |
| Ctrl+B / Ctrl+F | 游標左/右移一字元 |
| Ctrl+U | 清除游標前至行首 |
| Ctrl+K | 清除游標後至行尾 |
| Ctrl+W | 刪除游標前一單字 |
| Ctrl+Y | 貼上上次刪除內容 |
| Ctrl+T | 交換游標前兩字元 |
| Ctrl+R | 搜尋歷史指令(輸入關鍵字) |
| Ctrl+L | 清除螢幕 (同 clear) |
| Ctrl+C | 終止目前進程 |
| Ctrl+D | 登出 Shell / 刪除游標上字元 |
| Ctrl+H / Backspace | 刪除游標前字元 |
| Ctrl+Z | 將前景工作暫停至背景 (用 fg 恢復) |