How to Capture a Screenshot From the Linux Terminal
Capture full screens, windows, regions, and delayed shots from Linux terminals with GNOME Screenshot, scrot, ImageMagick, KDE Spectacle, and more.
You can capture a Linux screenshot from the terminal with a desktop utility such as gnome-screenshot, scrot, ImageMagick’s import, or KDE’s spectacle. The right command depends on your desktop environment, display server, and whether you need a full screen, window, selected region, clipboard copy, or an unattended script.
1. Quick commands
Use the command that matches your immediate need:
| Task | Command |
|---|---|
| Full screen with GNOME | gnome-screenshot --file ~/Pictures/full.png |
| Active window with GNOME | gnome-screenshot --window --file ~/Pictures/window.png |
| Select an area with GNOME | gnome-screenshot --area --file ~/Pictures/area.png |
| Copy the screen to the clipboard | gnome-screenshot --clipboard |
| Delayed GNOME capture | gnome-screenshot --delay=5 --file ~/Pictures/delayed.png |
| Full screen with scrot | scrot ~/Pictures/full.png |
| Select a rectangle with scrot | scrot -s ~/Pictures/area.png |
| Delayed scrot capture | scrot -d 5 ~/Pictures/delayed.png |
| Send scrot image data to stdout | scrot - |
| Capture the X server root window | magick import -window root ~/Pictures/full.png |
These commands target a local graphical session. A terminal opened through SSH cannot capture a user’s desktop unless it can reach the graphical display server and has the required authorization.
2. GNOME Screenshot
For a GNOME desktop running an X11 session, gnome-screenshot is usually the simplest integrated command. Debian’s manual documents full-screen, active-window, area, clipboard, pointer, and delay options.
Install it
# Debian or Ubuntu
sudo apt update
sudo apt install gnome-screenshot
# Fedora
sudo dnf install gnome-screenshot
# Arch Linux
sudo pacman -S gnome-screenshot
Capture modes
# Entire screen
gnome-screenshot --file ~/Pictures/full.png
# Active window
gnome-screenshot --window --file ~/Pictures/window.png
# Select a rectangular area
gnome-screenshot --area --file ~/Pictures/area.png
# Copy a capture to the desktop clipboard
gnome-screenshot --clipboard
# Wait five seconds before capturing
gnome-screenshot --delay=5 --file ~/Pictures/delayed.png
Use an absolute path when a script will run from an unknown working directory. Create the destination directory first if it might not exist:
mkdir -p "$HOME/Pictures"
gnome-screenshot --file "$HOME/Pictures/terminal-$(date +%Y%m%d-%H%M%S).png"
3. Scrot for repeatable X11 scripts
scrot is a compact, script-friendly X11 utility. Its manual documents file output, interactive selection, delays, window capture, formats, quality controls, and stdout output.
# Debian or Ubuntu
sudo apt update
sudo apt install scrot
# Full screen
scrot "$HOME/Pictures/full.png"
# Select a rectangle interactively
scrot -s "$HOME/Pictures/area.png"
# Wait five seconds
scrot -d 5 "$HOME/Pictures/delayed.png"
# Write image data to standard output
scrot -
Because scrot - writes image data to standard output, it can feed another command. For example, save a timestamped file while keeping the capture command reusable:
mkdir -p "$HOME/Pictures"
scrot - > "$HOME/Pictures/capture-$(date +%s).png"
Check scrot --help on your distribution for the exact window, format, and quality flags available in its packaged version.
4. ImageMagick import
ImageMagick is useful when the screenshot is the first step in an image-processing pipeline. Its official documentation describes import as capturing some or all of an X server and saving it to a file.
# Install
sudo apt update
sudo apt install imagemagick
# Select a window or region interactively
magick import "$HOME/Pictures/capture.png"
# Capture the whole X server screen
magick import -window root "$HOME/Pictures/full.png"
You can pass the resulting file to other ImageMagick operations, such as resizing or converting formats:
magick import -window root /tmp/full.png
magick /tmp/full.png -resize 50% "$HOME/Pictures/full-small.jpg"
5. KDE Spectacle
KDE Plasma users can use Spectacle from the command line. KDE documents command-line options and a background mode for scripted captures without showing the normal interactive window.
# Install on Debian or Ubuntu
sudo apt update
sudo apt install spectacle
# Inspect options on your installed version
spectacle --help
# Run the graphical capture tool
spectacle
Use the background and output options documented by the Spectacle version shipped with your distribution when building an unattended job. KDE’s documentation is the authoritative reference for those flags.
6. Flameshot for selection and annotation
Flameshot is useful when you want to select an area and annotate it before saving or copying. Its Linux documentation covers distribution packages, AppImage execution, and Flathub installation.
# Debian or Ubuntu package, when available
sudo apt update
sudo apt install flameshot
# Launch the interactive tool
flameshot gui
For other distributions, follow the installation method in the official Flameshot installation documentation. The interactive workflow is generally a better fit for a person at a desktop than for a headless batch job.
7. X11, Wayland, and display compatibility
The commands above do not provide one universal solution for every Linux display server. scrot and ImageMagick’s import explicitly target X11 or an X server. Under Wayland, an X11 command can fail, return a blank image, or capture only an XWayland surface.
Identify the current session before troubleshooting:
echo "$XDG_SESSION_TYPE"
# Common output: x11 or wayland
If the result is wayland, prefer the screenshot facility integrated with your compositor or desktop environment and check that compositor’s documentation for command-line or portal support. Do not assume that an X11 utility can capture protected Wayland surfaces.
8. Capturing from SSH or a headless machine
An SSH shell alone does not contain the graphical session. A capture requires a reachable display server, a valid display variable, and authorization for the desktop user.
echo "$DISPLAY"
echo "$WAYLAND_DISPLAY"
printenv XAUTHORITY
An empty DISPLAY usually means there is no X11 display associated with the shell. Setting a guessed value such as :0 is not sufficient if the SSH user lacks permission or the machine is running Wayland. For unattended server-side rendering, use a browser screenshot service instead of trying to expose a user’s desktop session.
9. Common options and output choices
File names and directories
output="$HOME/Pictures/screenshot-$(date +%Y%m%d-%H%M%S).png"
mkdir -p "$(dirname "$output")"
gnome-screenshot --file "$output"
Quote paths so spaces and shell metacharacters do not corrupt the destination.
PNG, JPEG, and other formats
PNG is a good default for terminal text and sharp UI edges. JPEG is smaller for photographic content but introduces compression artifacts around text. Scrot and ImageMagick support format and quality controls; consult the installed command’s help for exact syntax.
Clipboard versus files
Use gnome-screenshot --clipboard when the next step is pasting into a local application. Use a file or stdout when another script, archival process, or upload needs the bytes.
10. Troubleshooting checklist
| Symptom | Likely cause | Fix |
|---|---|---|
command not found |
The utility is not installed. | Install the package for your distribution, then run command --help. |
| Blank or black image | An X11 tool is being used on Wayland, or the target is protected. | Use the compositor’s native screenshot facility and verify XDG_SESSION_TYPE. |
Can't open display |
DISPLAY is unset or inaccessible. |
Run in the logged-in graphical session or configure a permitted display connection; an SSH shell by itself is not enough. |
| Permission denied writing file | The destination directory is missing or not writable. | Use a directory owned by the current user, create it with mkdir -p, and quote the path. |
| Interactive selection never appears | The command is running without a desktop or from a non-interactive session. | Use a full-screen unattended mode, or run the selection command inside the local desktop session. |
| Only one monitor is captured | The utility or compositor defines a different screen/monitor model. | Read the installed tool’s help and desktop documentation; test full-screen and window modes separately. |
| Clipboard option appears to do nothing | The command ran outside the desktop clipboard session. | Run it from the logged-in desktop and paste into a local application to verify. |
11. Automation, reliability, and performance
- Prefer deterministic paths: include a timestamp or job identifier and create the output directory before capture.
- Check exit status: in shell scripts, stop or report failure when the command returns a non-zero status.
- Keep interactive commands out of CI: area selection and annotation require a user and a graphical session.
- Account for display-server changes: an upgrade from X11 to Wayland can change whether an existing script works.
- Manage file size: PNG preserves text detail but can be large; convert or resize after capture when storage or transfer time matters.
- Use delays deliberately: a delay helps a menu or window appear, but it also increases job duration and can make automation flaky if the desktop changes.
For repeated browser-page captures, desktop screenshot commands capture whatever is visible on the local screen. They do not provide browser navigation, cookie handling, page-load waits, full-page scrolling, or element selection. A browser-aware API is more reliable for that workload.
12. Or skip the browser setup
If your goal is a screenshot of a website rather than the Linux desktop, ScreenshotNeo accepts one GET request and returns a PNG, JPEG, WebP, or PDF. Before capture it accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the result with X-Page-Verdict and X-Billed headers.
See the ScreenshotNeo API documentation for all options, including full-page capture, CSS-element capture, device presets, custom CSS and JavaScript, waits, headers, cookies, blocking rules, PDF settings, caching, signed links, asynchronous jobs, bulk capture, and usage data.
cURL
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
Python
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
Node.js
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
ScreenshotNeo also provides an MCP server with take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The Free plan includes 1,000 screenshots each month with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.
13. Frequently asked questions
Can I take a screenshot with only SSH?
Only when the SSH session can access an active graphical display and its authorization. A plain headless shell has no screen to capture.
Which command is best for GNOME?
Start with gnome-screenshot for full-screen, window, area, clipboard, and delayed captures.
Which tool is best for scripts?
scrot is compact and supports file output, delays, selection, and stdout on X11. ImageMagick is a better fit when conversion or other image processing follows capture.
Why does my screenshot work on X11 but fail on Wayland?
The cited X11 tools depend on an X server. Use the screenshot interface provided by your Wayland compositor or desktop and follow its documentation.
How do I screenshot a website without opening a desktop browser?
Use a browser-aware service such as ScreenshotNeo, which handles page loading and returns an image or PDF through its API.


