Post actualizado el día octubre 28, 2026 by DeiviSanzPlay
Capturing a screenshot from the Linux terminal is not a single command—it is a small configuration project. Different display servers (X11 vs. Wayland), different desktop environments, and different session types each change what works. This walkthrough focuses on getting a reliable, repeatable setup in place: installing the right tools, testing them, wiring up keyboard shortcuts, handling delays and region selection, and knowing where the approach breaks down.
Everything below assumes a reasonably modern distribution (Debian/Ubuntu 24.04+, Fedora 40+, Arch current). Commands are shown for the terminal, but the goal is a configuration you can invoke without opening a terminal every time.
Step 0: Identify Your Display Server First
Before installing anything, run:
echo $XDG_SESSION_TYPEYou will get x11 or wayland. This single line determines the rest of the setup. Most screenshot utilities written before 2020 assume X11 and will fail silently or produce a black image under Wayland. That silent black image is the most common complaint I see in support threads, and it almost always comes down to running an X11 tool inside a Wayland session.
You can also confirm with:
loginctl show-session $(loginctl | awk ‘/tty/{print $1; exit}’) -p TypeIf you are on Wayland, GNOME and KDE Plasma each expose their own screenshot interfaces through D-Bus, which is why the tool choice matters more than the command syntax.
Step 1: Install the Core Tools
The practical baseline is two packages: scrot (simple X11 grabber) and maim (a maintained fork of scrot with better region selection and piping support). On Wayland, add grim and slurp.
Debian / Ubuntu / Linux Mint
sudo apt update sudo apt install scrot maim grim slurp imagemagick xclipFedora
sudo dnf install scrot maim grim slurp ImageMagick xclipArch / Manjaro
sudo pacman -S scrot maim grim slurp imagemagick xclipimagemagick matters more than people expect. It gives you convert and identify, which you will need for cropping, format conversion, and verifying that a file is not a 0-byte or all-black capture. xclip lets you pipe a screenshot directly to the clipboard, which is often more useful than saving a file at all.
Step 2: Run Your First Verified Capture
Do not trust a command until you have confirmed the output. Start with a full-screen grab under X11:
maim ~/Pictures/test-full.pngThen verify it is not empty:
identify -format «%wx%h %bn» ~/Pictures/test-full.pngYou should see something like 1920×1080 412KB. If the dimensions are correct but the size is suspiciously small (under ~20KB for a full desktop), or if the image is pure black, you are almost certainly running an X11 tool on Wayland. Switch to grim:
grim ~/Pictures/test-wayland.pngUnder Wayland, grim talks to the compositor directly. It will work on Sway, Hyprland, and most wlroots-based compositors. It will not work on GNOME Wayland without the xdg-desktop-portal-gnome backend installed and running, because GNOME restricts direct framebuffer access. That is a real limitation and it catches people out constantly.
Step 3: Configure Region Selection
Full-screen captures are rarely what you want. Interactive region selection is the configuration most people actually need.
X11 with maim and slop
Install slop (part of the maim project) and chain it:
sudo apt install slop maim -s -o ~/Pictures/region-$(date +%Y%m%d-%H%M%S).pngThe -s flag triggers interactive selection; -o suppresses the cursor. Using $(date …) in the filename avoids overwriting previous captures, which is a habit worth building early.
Wayland with grim and slurp
grim -g «$(slurp)» ~/Pictures/region-$(date +%Y%m%d-%H%M%S).pngslurp returns geometry in the format X,Y WxH, which grim -g consumes directly. If slurp returns nothing, you cancelled the selection or your compositor does not expose the layer-shell protocol it needs.
Step 4: Add a Delay for Menus and Tooltips
Any screenshot of an open menu or dropdown needs a delay. Without one, the menu closes before the capture fires.
maim -d 3 ~/Pictures/delayed.png grim -d 3 ~/Pictures/delayed.pngThree seconds is usually enough to open a menu and position it. For context menus triggered by right-click, five seconds is safer. Note that sleep 3 && maim … is not equivalent—the delay flag keeps the tool in a state where it can still capture the pointer properly, whereas a shell sleep followed by an immediate grab sometimes misses transient UI.
Step 5: Pipe Directly to the Clipboard
Saving a file is often unnecessary. If you are documenting a bug or pasting into a chat, the clipboard is the destination.
maim -s | xclip -selection clipboard -t image/pngUnder Wayland, use wl-copy from the wl-clipboard package:
grim -g «$(slurp)» – | wl-copyThe trailing dash tells grim to write to stdout. This is the single most useful pattern in the whole setup, and it is the one I use daily.
Step 6: Wire Up Keyboard Shortcuts
The terminal command is only half the configuration. The other half is binding it.
GNOME
Open Settings → Keyboard → View and Customize Shortcuts → Custom Shortcuts. Add an entry with the command:
sh -c ‘grim -g «$(slurp)» – | wl-copy’The sh -c wrapper is required because GNOME does not run shortcuts through a shell, so the command substitution would never expand.
KDE Plasma
System Settings → Shortcuts → Custom → New → Command/URL. Plasma actually ships a built-in Spectacle tool with a D-Bus interface, which is more reliable than an external binary:
spectacle –region –background –clipboardUsing Spectacle avoids the portal permission prompt that appears the first time a third-party tool tries to capture under Plasma Wayland.
i3 / Sway
In your config file:
# i3 (X11) bindsym $mod+Print exec maim -s | xclip -selection clipboard -t image/png # Sway (Wayland) bindsym $mod+Print exec grim -g «$(slurp)» – | wl-copySway expands $(…) because it runs binds through its own shell. i3 does not, so you may need exec –no-startup-id sh -c ‘…’ depending on your version.
Step 7: Build a Reusable Script
Once you have three or four variants, a wrapper script pays for itself. Save this as ~/bin/shot and chmod +x it:
#!/usr/bin/env bash set -euo pipefail DIR=»$HOME/Pictures/Screenshots» mkdir -p «$DIR» STAMP=$(date +%Y%m%d-%H%M%S) case «${1:-region}» in full) if [ «$XDG_SESSION_TYPE» = wayland ]; then grim «$DIR/full-$STAMP.png» else maim «$DIR/full-$STAMP.png» fi ;; region) if [ «$XDG_SESSION_TYPE» = wayland ]; then grim -g «$(slurp)» «$DIR/region-$STAMP.png» else maim -s «$DIR/region-$STAMP.png» fi ;; clip) if [ «$XDG_SESSION_TYPE» = wayland ]; then grim -g «$(slurp)» – | wl-copy else maim -s | xclip -selection clipboard -t image/png fi ;; *) echo «usage: shot [full|region|clip]» >&2 exit 1 ;; esacNow every shortcut and every manual invocation routes through one file. Changing behavior later means editing one script, not five keyboard shortcuts.
Common Failures and What They Actually Mean
«Cannot open display»
You are running the command over SSH without an X forwarding session, or you are running it as root while your desktop session belongs to your user. Screenshots require access to the active session’s display socket. sudo maim will fail where maim succeeds. This is a permissions boundary, not a bug.
Black or empty image under Wayland
Covered above: wrong tool for the session type. Confirm with echo $XDG_SESSION_TYPE and switch to grim.
Region selection returns an error
slop and slurp need to draw an overlay window. If your compositor blocks overlay layers—some tiling setups do by default—selection will fail. Workaround: capture full screen and crop with ImageMagick:
convert full.png -crop 800×600+200+150 +repage cropped.pngMulti-monitor captures only grab one screen
maim and grim default to the whole virtual desktop on X11, but grim under Wayland captures the focused output unless you specify. Use grim -o DP-1 for a specific monitor, or check grim -l to list available outputs.
What This Setup Does Not Cover
Two honest limitations. First, capturing a single application window by clicking it requires either maim -i $(xdotool selectwindow) on X11 (which needs xdotool installed) or compositor-specific tooling on Wayland—there is no universal command. Second, screenshot tools cannot capture content protected by DRM or secure surfaces (streaming video, some banking apps, password manager overlays). The compositor will return black in those regions by design, and no flag will override it.
Also worth knowing: on systems with fractional scaling, captures sometimes come out at the wrong resolution because the compositor reports logical coordinates while the framebuffer is physical. If your images look soft or cropped at the edges, check your scale factor before assuming the tool is broken.
Verification Checklist
Before considering the configuration complete, confirm each of these:
- echo $XDG_SESSION_TYPE returns the value you built around.
- A full-screen capture produces a file over 100KB with correct dimensions per identify.
- Region selection works and produces a cropped result.
- Clipboard piping pastes into an image-aware application.
- The keyboard shortcut fires without opening a terminal.
- A delayed capture successfully grabs an open menu.
If all six pass, the setup is solid. If the clipboard step fails but file saving works, you are missing xclip or wl-clipboard—a dependency issue, not a configuration error.
The broader point: screenshotting from the Linux terminal is less about memorizing a command and more about matching the tool to the session type and then wrapping the result so it is reachable without thinking. Get the wrapper script right once and the rest becomes muscle memory.
Perfiles verificables: Sitio web
Publicado el 28 de October de 2026. Última revisión: 28 de October de 2026.