DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
Bash

How to Take Desktop Screenshots in Bash on X11 and Wayland

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The right Bash command depends on your display session. On X11, use scrot screenshot.png or ImageMagick’s import -window root screenshot.png. On a Wayland compositor that supports the required screencopy protocol, use grim screenshot.png; for a selected rectangle, use grim -g "$(slurp)" screenshot.png. Check whether you are running X11 or Wayland before choosing a tool, because no single command captures every Linux desktop.

Choose the command for your display server

Bash is only launching a desktop capture utility. The utility must be able to talk to your session’s display protocol, and the compositor must expose the capture interfaces it expects.

Session or environment Full-screen command Region or other target Important dependency
Wayland with grim screencopy support grim screenshot.png grim -g "$(slurp)" screenshot.png Compatible compositor; slurp for selection
X11 scrot screenshot.png Use scrot’s window/rectangle options or ImageMagick An X server and installed utility
GNOME desktop tool Use gnome-screenshot --help for the installed version Full screen, active window, area, clipboard and delay options are documented Option spelling varies by version
KDE Plasma Use spectacle --help Choose the mode and output options supported by your release Flags vary with the installed Spectacle version

To identify the session, run:

printf '%sn' "${XDG_SESSION_TYPE:-unknown}"

Typical output is x11 or wayland. If it is empty or unexpected, inspect your desktop’s session settings and test the command’s own help output.

Wayland: capture the desktop with grim

Save a full desktop image

grim writes PNG by default. Save the current capture to a named file:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB
  • CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
  • WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
  • A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents
grim screenshot.png

With no output filename, grim’s default output handling captures all outputs:

grim

For scripts that need image bytes rather than a file, write to standard output:

grim -

The grim manual documents output selection, cursor inclusion and layout coordinates. Exact flags should be checked with the version installed on your system:

grim --help

Select a rectangle interactively

slurp is a separate region selector. Its output is a geometry string that grim accepts with -g:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
grim -g "$(slurp)" screenshot.png

This requires both a compositor with grim’s screencopy protocol and a working slurp integration. If selection cancels, no useful geometry is passed to grim; check slurp independently with slurp.

Copy a Wayland screenshot to the clipboard

wl-copy is a separate clipboard utility. The grim project documentation demonstrates this pipeline:

Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
  • SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
grim - | wl-copy

This keeps the image in memory and sends it to the Wayland clipboard instead of creating a file. Verify that a Wayland clipboard implementation is installed if the command reports that wl-copy is missing.

X11: use scrot or ImageMagick

Simple scripted capture with scrot

On X11, scrot is a command-line screenshot utility designed for scriptable operation:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
scrot screenshot.png

It can save multiple image formats and supports capturing a specific window or rectangle. Consult the local manual for the exact option syntax on your distribution:

scrot --help

Use a unique filename when running repeated jobs. Bash’s date expansion is convenient:

scrot "desktop-$(date +%Y%m%d-%H%M%S).png"

Capture the X server’s root window with ImageMagick

ImageMagick documents this X11 form:

import -window root screenshot.png

Some installations expose the subcommand through the magick launcher. If import is not recognized, try:

magick import -window root screenshot.png

Command names differ between ImageMagick versions, so ask the installed binary for help:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
  • Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
  • Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
  • In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
  • Ultra-thin bezels: Maximize your viewing experience with thin bezels.
import -help
magick import -help

These commands address an X server. They are not a general native-Wayland solution; running them under Wayland may fail or capture only an Xwayland surface, depending on the environment.

GNOME and KDE command-line tools

GNOME Screenshot

GNOME’s gnome-screenshot utility documents full-screen, active-window and area capture, plus clipboard, delay and output-file options. Because option spelling and availability depend on the installed release, start with:

gnome-screenshot --help

Then select the documented mode and output path for that version. If a flag from an online example is rejected, use the local man page:

man gnome-screenshot

KDE Spectacle

KDE Spectacle can be started from a shell. Its command-line interface and background, output-file and capture-mode options are version-dependent:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
spectacle --help

The KDE handbook describes command-line startup at KDE’s Spectacle documentation. Prefer the help output shipped with your installation when writing scripts that must survive upgrades.

Build reliable Bash scripts

Fail clearly when a dependency is absent

#!/usr/bin/env bash
set -euo pipefail

out="${1:-screenshot.png}"

if [[ "${XDG_SESSION_TYPE:-}" == "wayland" ]]; then
  command -v grim >/dev/null || { echo "grim is required on Wayland" >&2; exit 1; }
  grim "$out"
elif [[ "${XDG_SESSION_TYPE:-}" == "x11" ]]; then
  command -v scrot >/dev/null || { echo "scrot is required on X11" >&2; exit 1; }
  scrot "$out"
else
  echo "Set up an X11 or Wayland graphical session before capturing" >&2
  exit 1
fi

printf 'Saved %sn' "$out"

This deliberately does not pretend that protocol detection guarantees compositor support. A Wayland session can still lack grim’s required screencopy interface.

Rank #4
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor
  • CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
  • SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
  • MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
  • KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
  • INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient

Check the result in a script

if [[ -s screenshot.png ]]; then
  printf 'Capture succeeded: %s bytesn' "$(wc -c < screenshot.png)"
else
  printf 'Capture failed or produced an empty filen' >&2
  exit 1
fi

Use absolute paths in cron-like jobs, create the destination directory first, and remember that a graphical session’s environment may not be available to non-interactive services.

Common failures and fixes

“Cannot open display” or an X11 connection error

You may be running an X11 utility without an X server connection, or from a shell that lacks the session’s display environment. Confirm XDG_SESSION_TYPE, run the command inside the logged-in desktop session, and use grim for native Wayland.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Grim reports missing screencopy support

Grim currently requires screencopy support from the compositor. Update or configure the compositor if that interface is available, or use its supported screenshot utility. This is an environment limitation, not a Bash quoting problem.

The region command fails

Install and test slurp separately. Confirm that the compositor supports both grim’s capture path and slurp’s selection protocol, then quote the command substitution exactly:

grim -g "$(slurp)" screenshot.png

“Command not found”

Install the utility from your distribution, or choose a tool already provided by GNOME or KDE. Check the binary and its options with command -v grim, command -v scrot, or --help.

The file is created but cannot be opened

Check that the directory is writable and that the file is non-empty. A relative path is resolved from the shell’s current directory, which may differ when a script is launched by another program.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
  • 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
  • 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.

Wayland captures differ between desktops

Wayland defines compositor protocols rather than one universal screenshot command. A compositor may omit a protocol or impose permission behavior. Treat grim support as a capability to test, not as a guarantee for every Wayland desktop. A GNOME community report illustrates why one configuration’s limitation should not be generalized to all GNOME systems: the reported issue.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Performance, formats and automation choices

  • PNG: Grim’s documented default is PNG, which is lossless and convenient for clipboard workflows.
  • File versus clipboard: A filename creates a reusable artifact; stdout and wl-copy avoid an intermediate file.
  • Full desktop versus region: Full-output captures are simplest; region selection adds slurp and compositor integration.
  • Desktop wrapper: Tools such as gscreenshot present multiple backends, but their functionality and dependencies vary by configuration.
  • Maintenance: The grim GitHub repository is archived and points to a move to SourceHut. Its README remains useful for examples, while your distribution’s current manual is the better reference for available flags.

Or skip the browser setup

If what you need is a screenshot of a website rather than the pixels on your Linux desktop, ScreenshotNeo provides a one-request website screenshot API and MCP server. It is a different workflow from grim or scrot: the service loads a URL and returns PNG, JPEG, WebP or PDF.

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}`);

See the ScreenshotNeo documentation for authentication, options and response headers. Before capture it accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups and chat widgets; each cleanup step can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads and cache hits cost nothing, and the response identifies the page verdict and billing status with X-Page-Verdict and X-Billed headers. Its MCP server exposes take_screenshot, get_page_info and capture_pdf to Claude, Cursor and other MCP clients.

Every plan includes its feature set, including full-page lazy-image loading, CSS-selector element capture, dark mode, device presets, retina scale, PDF controls, custom CSS and JavaScript, clicks, waits, request blocking, headers, cookies, user agent, authorization, timezone, geolocation, transparent backgrounds, resizing, selectable-TTL caching, signed links, asynchronous webhooks, bulk capture of up to 100 URLs per call, usage data and an OpenAPI specification. The service also accepts parameter names used by other screenshot APIs, which can simplify migration.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Plan Allowance and price
Free 1,000 shots/month, no card
Starter $5 for 3,000 shots
Growth $15 for 15,000 shots
Pro $39 for 60,000 shots
Scale $99 for 250,000 shots
Business $249 for 1,000,000 shots

Yearly billing gives two months free. Start with 1,000 free screenshots a month and no card.

Further references

Frequently Asked Questions

Can I use scrot on Wayland?

Scrot targets an X server. Use grim when your Wayland compositor provides the required screencopy protocol; scrot is not a general native-Wayland capture method.

Is slurp included with grim?

No. Slurp is a separate interactive region selector used by the command substitution in grim -g "$(slurp)" screenshot.png.

How do I capture only the active window?

Use the active-window mode documented by your desktop utility, such as gnome-screenshot --help on GNOME or spectacle --help on KDE. The exact flags depend on the installed version.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Read next

Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.