萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 作業系統 >  >> Linux 教學

Linux 終端機截圖神器 scrot 完整使用教學:安裝、全螢幕/區域/延遲/縮圖/管道傳遞實戰

scrot (SCReen shOT) 是輕量級命令列截圖工具,支援全螢幕、視窗選取、矩形區域、延遲截圖、品質/縮圖調整、管道傳遞後處理等功能,適合無圖形介面伺服器、腳本自動化、極簡桌面環境。本文提供跨發行版安裝、六大核心用法實戰與進階技巧。

一、 跨平台安裝

發行版安裝指令
Debian / Ubuntu / Mintsudo apt-get install scrot
Fedora / RHEL / CentOS (EPEL)sudo yum install scrot
Arch / Manjarosudo pacman -S scrot
CentOS 7 無 EPEL 時源碼編譯
yum install giblib-devel
wget https://linuxbrit.co.uk/downloads/scrot-0.8.tar.gz
tar xzf scrot-0.8.tar.gz && cd scrot-0.8
./configure && make && sudo make install

二、 六大核心用法實戰

1. 全螢幕截圖 (預設 PNG、當前目錄、檔名含時間戳)


scrot
# 輸出例:2023-10-15-143020_1920x1080_scrot.png
scrot ~/Pictures/fullscreen.png  # 指定路徑/檔名

2. 互動選取視窗或矩形區域


scrot -s
# 執行後滑鼠游標變十字,點選視窗或拖曳框選區域,釋放完成截圖

3. 延遲截圖 (準備選單/工具提示/通知)


scrot -d 5          # 延遲 5 秒全螢幕
scrot -s -d 3       # 延遲 3 秒後進入區域選取
scrot -d 10 -c      # -c 倒數顯示秒數 (標準輸出)

4. 調整圖片品質 (1-100,預設 75)


scrot -q 90         # 高品質
scrot -q 30         # 低品質,檔案極小

5. 產生縮圖 (原圖百分比 1-100)


scrot -t 20         # 同目錄產生 20% 縮圖,檔名尾綴 _thumb
# 原圖:shot.png → 縮圖:shot_thumb.png

6. 管道傳遞後處理 (最強功能)


# 截圖後自動移動至 ~/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
copyright © 萬盛學電腦網 all rights reserved