scrot (SCReen shOT) 是輕量級命令列截圖工具,支援全螢幕、視窗選取、矩形區域、延遲截圖、品質/縮圖調整、管道傳遞後處理等功能,適合無圖形介面伺服器、腳本自動化、極簡桌面環境。本文提供跨發行版安裝、六大核心用法實戰與進階技巧。
| 發行版 | 安裝指令 |
|---|---|
| Debian / Ubuntu / Mint | sudo apt-get install scrot |
| Fedora / RHEL / CentOS (EPEL) | sudo yum install scrot |
| Arch / Manjaro | sudo pacman -S scrot |
| CentOS 7 無 EPEL 時源碼編譯 |
|
scrot
# 輸出例:2023-10-15-143020_1920x1080_scrot.png
scrot ~/Pictures/fullscreen.png # 指定路徑/檔名
scrot -s
# 執行後滑鼠游標變十字,點選視窗或拖曳框選區域,釋放完成截圖
scrot -d 5 # 延遲 5 秒全螢幕
scrot -s -d 3 # 延遲 3 秒後進入區域選取
scrot -d 10 -c # -c 倒數顯示秒數 (標準輸出)
scrot -q 90 # 高品質
scrot -q 30 # 低品質,檔案極小
scrot -t 20 # 同目錄產生 20% 縮圖,檔名尾綴 _thumb
# 原圖:shot.png → 縮圖:shot_thumb.png
# 截圖後自動移動至 ~/screenshots/
scrot -e 'mv $f ~/screenshots/'
# 截圖並上傳至圖床 (需 curl + API)
scrot -e 'curl -F "file=@$f" https://img.example.com/api/upload'
# 截圖並用 ImageMagick 加浮水印
scrot -e 'convert $f -gravity southeast -annotate +10+10 "watermark" $f'
# 多重處理 (分號分隔)
scrot -e 'mv $f ~/shots/; notify-send "截圖完成" "$f"'
$f 為截圖檔案完整路徑,$n 為檔名不含路徑,$w $h 為寬高。
# 延遲 3 秒、選取區域、品質 80%、產生 25% 縮圖、自動歸檔並通知
scrot -s -d 3 -q 80 -t 25 -e 'mv $f ~/shots/; mv ${f}_thumb ~/shots/; notify-send "截圖完成" "$f"'
# 腳本化:每小時截圖記錄桌面狀態 (cron)
0 * * * * DISPLAY=:0 scrot -q 50 -e 'mv $f /var/log/desktop_snapshots/'
| 問題 | 解決/替代 |
|---|---|
| Wayland 下無法截圖 | scrot 基於 X11,Wayland 改用 grim + slurp (選區) 或 spectacle (KDE) |
| 多螢幕僅截主螢幕 | scrot 單螢幕支援,多螢幕用 import -window root (ImageMagick) 或 maim |
| 需錄製 GIF/影片 | 使用 peek、vokoscreenNG、ffmpeg x11grab |