Capturing screenshots on Linux helps document issues, preserve configuration states, and share exact visuals with teammates or support. When work happens primarily in terminals or over SSH, depending on desktop screenshot tools quickly becomes inconvenient or impossible.

On systems running an X11 session, common graphical utilities simply capture the contents of the root window or an individual application window. The ImageMagick toolkit includes the import command, which talks directly to the X server and saves images in formats such as PNG or JPEG, making it convenient to drive screenshots from a shell script or single terminal command.

Because import connects to the active display, a working graphical session and the correct DISPLAY and XAUTHORITY environment are required; capturing a pure virtual console (for example on tty1 without X) is not supported. On remote servers reached via SSH, either X11 forwarding or a virtual framebuffer such as Xvfb is necessary for screenshot support, and using timestamped filenames helps avoid overwriting previous captures and keeps images organized.

Steps to take a screenshot in Linux using the command line:

  1. Open a terminal on a Linux system with access to a graphical X11 session.
  2. Install ImageMagick and Xvfb on the system if they are not already present.
    $ sudo apt update
    Hit:1 http://ports.ubuntu.com/ubuntu-ports noble InRelease
    Hit:2 http://ports.ubuntu.com/ubuntu-ports noble-updates InRelease
    Hit:3 http://ports.ubuntu.com/ubuntu-ports noble-backports InRelease
    Hit:4 http://ports.ubuntu.com/ubuntu-ports noble-security InRelease
    Reading package lists...
    Building dependency tree...
    Reading state information...
    5 packages can be upgraded. Run 'apt list --upgradable' to see them.
    $ sudo apt install --assume-yes imagemagick xvfb x11-xserver-utils
    Reading package lists...
    Building dependency tree...
    Reading state information...
    imagemagick is already the newest version (8:6.9.12.98+dfsg1-5.2build2).
    xvfb is already the newest version (2:21.1.12-1ubuntu1.5).
    x11-xserver-utils is already the newest version (7.7+10build2).
    0 upgraded, 0 newly installed, 0 to remove and 5 not upgraded.

    This command uses apt on Ubuntu and Debian systems; use the equivalent package manager command on other distributions, such as dnf on RHEL-based systems or zypper on openSUSE.

  3. Use Xvfb with import to capture a full-screen screenshot in a headless session.
    $ xvfb-run -a bash -c 'xsetroot -solid #263238; import -window root -pause 1 /root/sg-work/Screenshot-virtual.png'

    Capture options:

    • -window root: capture the entire screen.
    • -pause 1: wait one second before taking the screenshot.
    • /root/sg-work/Screenshot-virtual.png: output filename for the capture.

    More options for import:

    $ import -help | head -n 4
    Version: ImageMagick 6.9.12-98 Q16 aarch64 18038 https://legacy.imagemagick.org
    Copyright: (C) 1999 ImageMagick Studio LLC
    License: https://imagemagick.org/script/license.php
    Features: Cipher DPC Modules OpenMP(4.5)
  4. Verify that the screenshot file was created and recognized as an image.
    $ file /root/sg-work/Screenshot-virtual.png
    /root/sg-work/Screenshot-virtual.png: PNG image data, 1280 x 1024, 1-bit grayscale, non-interlaced
  5. Optionally process the screenshot further with other ImageMagick tools such as convert or mogrify to resize, crop, or annotate the image.