October 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 NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
Command Line

How to Take a Screenshot from the Linux Command Line (X11, Wayland, Flameshot, scrot and ImageMagick)

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.

The right Linux screenshot command depends on your display session. On X11, magick import and scrot are straightforward choices; on Wayland, use a portal-aware tool such as current Flameshot with the correct desktop backend. For an interactive area selection, run flameshot gui. For a simple X11 capture, run magick import screenshot.png. For a small script, run scrot screenshot.png.

First identify whether the session is X11 or Wayland, then choose the capture mode, destination and automation level you need.

1. Check whether you are running X11 or Wayland

Some screenshot utilities talk directly to an X server, while Wayland normally requires a desktop portal to ask the compositor for permission. A command that works on X11 is not automatically a Wayland command.

  1. Print the session type:
    printf '%sn' "$XDG_SESSION_TYPE"
  2. Read the result. x11 means an X server session; wayland means a Wayland session. An empty or unusual value means you should check your login manager and desktop settings before troubleshooting the capture tool.
  3. Identify the desktop or compositor if a portal error appears. GNOME, KDE and Hyprland use different portal backends, and a minimal window manager may not have a screenshot-capable backend installed.

The commands below state their session assumptions explicitly. ImageMagick’s import command is documented for an X server. Flameshot version 14 and later uses XDG Desktop Portal capture, including on X11; its legacy native X11 mode is for minimal X11 setups and is ignored on Wayland.

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

2. Use Flameshot for interactive captures

Flameshot is the most convenient choice when you want to drag a rectangle, annotate it, copy it, or save it without building a longer command. Its command-line interface provides separate GUI, monitor and all-monitor modes.

Select a region interactively

flameshot gui

A selection overlay appears. Drag over the region, then use the action controls to save, copy or annotate it. To save directly into a directory:

flameshot gui --path "$HOME/Pictures"

Flameshot chooses a filename in that directory. Create the directory first if it does not exist:

mkdir -p "$HOME/Pictures"
flameshot gui --path "$HOME/Pictures"

Copy the selection to the clipboard

flameshot gui --clipboard

This is useful when the destination is an editor, issue tracker or chat application rather than a file.

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

Wait before displaying the selection

flameshot gui --delay 2000

The delay is in milliseconds, so 2000 waits two seconds. A delay helps when you need to open a menu or change a window before selecting the area.

Capture one monitor or every monitor

Use screen for one monitor. The monitor containing the pointer is the default; select a monitor explicitly with --number:

flameshot screen --number 0 --path "$HOME/Pictures"

Use full to capture all monitors as one image:

flameshot full --path "$HOME/Pictures"

Monitor numbering is environment-dependent. If monitor 0 is not the display you expect, try the next number.

Automation-oriented Flameshot output

The CLI also supports a specified region, the last selected region, raw PNG output to standard output, geometry reporting, pinning, uploading and accepting a selection immediately. Option names can vary with the installed release, so inspect the local help before putting an option in a production script:

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

Replace the accidental-looking second command with the actual executable if you copy commands into a script:

flameshot gui --help

The --upload action transmits the screenshot to an online service. Treat it as a data transfer, not as another way to save locally; do not use it for confidential screen content unless you have selected and trust the destination.

3. Capture an X11 screen with ImageMagick

ImageMagick’s import utility captures part or all of an X server screen. It can interactively select an area or window, and it can write to a file or clipboard.

Interactive area or window

magick import screenshot.png

After running the command, select the window or rectangle according to the pointer instructions from ImageMagick. The result is written to screenshot.png; use a filename ending in .jpg or another supported format when that is preferable.

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.

Capture the complete X11 root screen

magick import -window root screen.png

This captures the X11 root window rather than waiting for an interactive selection. It is suitable for a one-shot command or a script running inside an X11 session.

Send the image to the clipboard

magick import clipboard:

Clipboard support depends on the desktop clipboard integration available on the machine. If the command completes but another application cannot paste the image, test a file destination first and inspect that application’s image-clipboard support.

4. Use scrot for a small, scriptable command

scrot is a simple command-line capture utility documented by Debian. It uses imlib2 and can save formats including PNG, JPEG and GIF. Package names and versions differ by distribution, so install the package supplied by your distribution before using it.

Save a basic screenshot

scrot screenshot.png

A named extension selects the output format in typical installations. A script can generate a timestamped name without overwriting an earlier capture:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
mkdir -p "$HOME/Pictures"
scrot "$HOME/Pictures/screen-$(date +%Y%m%d-%H%M%S).png"

Window, rectangle and delayed captures

Scrot documents window selection, rectangular-area selection, delays and quality controls. Exact switches can vary with the packaged version, so read the installed manual:

scrot --help
man scrot

Use the help output to confirm the switches for your distribution before embedding them in a script. This avoids copying an option from a different scrot release.

5. Which command should you choose?

Need Best starting point Session or limitation
Drag-select, annotate, save or copy flameshot gui On Wayland, a working screenshot portal and permission grant are required.
One monitor flameshot screen --number 0 Monitor numbering and portal behavior depend on the desktop.
All monitors together flameshot full Produces a combined multi-monitor capture.
Interactive X11 window or area magick import screenshot.png Documented for an X server, not a Wayland-native route.
Complete X11 root screen magick import -window root screen.png Requires an accessible X server.
Small script with a named file scrot screenshot.png Package availability and switches vary by distribution.
Clipboard destination Flameshot --clipboard or ImageMagick clipboard: Clipboard implementation must be available in the desktop session.

6. Wayland setup and permission problems

Portal backend missing

On Wayland, Flameshot asks the desktop portal to perform the capture. GNOME, KDE and Hyprland need the appropriate portal backend for the running desktop. Install and enable the backend packaged for your distribution, then log out and back in if the desktop does not discover it immediately.

Screenshot permission was denied

GNOME may display a permission prompt or require a screenshot permission step documented by Flameshot. Approve the request for the capture to proceed. If you rejected it, revisit the desktop’s permission or portal settings and retry.

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

Minimal X11 window manager

Some minimal X11 environments do not ship a screenshot-capable portal. Flameshot documents a legacy native X11 capture setting for this case. Enable it only in an X11 session; it is ignored on Wayland. The exact setting name and configuration path depend on the Flameshot release, so check flameshot config and the installed help.

Black, blank or incomplete result

  • Confirm XDG_SESSION_TYPE and stop using an X-server-only command in a Wayland session.
  • Check that the portal backend matches the active desktop, not merely an installed desktop you are not running.
  • Try a full-screen Flameshot capture before a window-specific selection to separate permission problems from window-selection problems.
  • On X11, verify that DISPLAY points to the active server and that the command is run as the logged-in desktop user.

7. Make captures reliable in scripts

Use absolute paths and create directories

set -eu
out="$HOME/Pictures/captures"
mkdir -p "$out"
file="$out/screen-$(date +%Y%m%d-%H%M%S).png"
scrot "$file"
printf 'Wrote %sn' "$file"

set -eu makes the shell stop on an error or unset variable. The final message gives callers a predictable success signal and path.

Prevent accidental overwrites

Timestamped names are simple, but two captures in the same second can still collide. Add nanoseconds where your shell and operating system provide them:

file="$HOME/Pictures/screen-$(date +%Y%m%d-%H%M%S-%N).png"

For portability, a temporary file followed by an atomic rename is safer when another process reads the directory concurrently.

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

Check the result before continuing

if [ ! -s "$file" ]; then
  printf 'Screenshot was not created: %sn' "$file" >&2
  exit 1
fi

A non-empty file is only a basic check. For important pipelines, also verify that the image decoder in your next step can open the file.

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

8. Common errors and fixes

command not found

Install the package using your distribution’s package manager, then confirm the executable with command -v flameshot, command -v scrot or command -v magick. ImageMagick installations sometimes provide a version-specific command layout; use magick --version to confirm the modern CLI is present.

Unable to open X display

This usually means ImageMagick is being run without an accessible X server, with the wrong DISPLAY, or from a non-graphical SSH/session context. Run it inside the logged-in X11 desktop, check printf '%sn' "$DISPLAY", and do not expect it to become Wayland-compatible by setting an arbitrary display value.

Flameshot opens but cannot capture

On Wayland, verify the portal backend and approve the screenshot permission. On minimal X11, consider Flameshot’s legacy native X11 mode. Check the installed version’s help because configuration labels change between releases.

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

The output is saved somewhere unexpected

Pass an absolute path, such as --path "$HOME/Pictures" or "$HOME/Pictures/file.png", and create the directory before capture. Relative paths are resolved from the command’s current working directory, which may differ when launched by a service or desktop shortcut.

A script hangs waiting for input

flameshot gui is intentionally interactive. Use screen, full or a non-interactive utility for unattended jobs. If you need a region, supply the documented region option for your installed Flameshot version and test it in the same desktop session used by the job.

9. Performance, security and cost considerations

Local captures normally cost no service fee, but they consume CPU, memory and disk while encoding and writing the image. PNG preserves exact pixels but can be larger; JPEG is smaller but introduces lossy compression. For repeated captures, reduce the capture area, choose the format your downstream tool needs, and avoid unnecessary multi-monitor images.

Screen images can contain passwords, tokens, private messages and customer data. Keep local files in a directory with appropriate permissions, avoid world-readable temporary folders, and review any upload option before using it. Flameshot’s upload action is an explicit transmission outside the machine.

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

Or skip the browser setup

If what you really need is a screenshot of a website rather than the Linux desktop, ScreenshotNeo returns a PNG, JPEG, WebP or PDF from one request. It accepts cookie and consent banners before capture, removes more than 60 known consent platforms plus newsletter popups and chat widgets, and lets you turn each cleanup step off. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed; response headers identify the page verdict and whether it was billed.

Its API supports full-page captures with lazy images loaded, CSS-selector element shots, dark mode, 12 device presets or custom viewports, retina scale, PDF paper size and page ranges, custom CSS and JavaScript, clicks, selector or network-idle waits, ad/tracker/request blocking, headers, cookies, user agents, authorization, timezone, geolocation, transparent backgrounds, resizing, chosen cache TTLs, signed image links, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, a usage API and an OpenAPI specification. Existing parameter names used by other screenshot APIs also work, easing migration.

One-call cURL example

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for authentication, output options and all capture parameters.

Python

import requests

r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
r.raise_for_status()
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}`);
if (!res.ok) throw new Error(`ScreenshotNeo returned ${res.status}`);
const fs = await import('node:fs/promises');
await fs.writeFile('shot.webp', Buffer.from(await res.arrayBuffer()));

Use it from an AI agent

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 shots each month with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.

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

FAQ

Can I use magick import on Wayland?

Its documentation describes an X-server capture path, so use a portal-aware Wayland tool instead of treating it as a universal command.

What is the simplest unattended command?

For an X11 script, scrot screenshot.png is the shortest starting point. Test the installed package’s options before adding window, delay or quality switches.

Why does Flameshot need a portal?

Current Flameshot guidance uses XDG Desktop Portal capture to obtain compositor-approved screenshots, including on X11 in version 14 and later.

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.

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

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
PC Slower Than It Used to Be?Free scan - under a minute

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.