Screenshot tools for the command line
Say Cheese
Linux is awash in desktop screenshot tools, but what if you want to take a quick screenshot from a terminal window?
Suppose you want to record the contents of a computer screen or window. Linux is blessed with a number of useful tools that capture the view on your screen at a given moment. You can use screenshots to preserve critical information, document the contents of web forms, or illustrate application procedures. Most of the popular screenshot tools, however, are desktop applications. What if you don't want to slow down and maneuver through a GUI just to capture the contents of your screen? Many users don't realize you can also create screenshots from the command line. Command-line screenshots are a quick and useful option when you are working in a terminal window, and conjuring up a screenshot through a one-line command means you can add screenshots to your Bash scripts. In this article, I'll show you three powerful screenshot utilities available in the Ubuntu 22.04 Linux command-line interface (CLI): scrot
, gnome-screenshot
, and import
.
scrot
SCReen shOT (scrot
) is a lightweight and simple command-line tool for capturing screenshots in Linux [1]. It offers a range of options and is highly configurable. To install scrot
on an Ubuntu 22.04 system (Figure 1), enter:
$ sudo apt install scrot
To capture a screenshot using scrot
, open a terminal and enter:
$ scrot myscreenshot.png
By default, scrot
captures the entire screen. However, you can also specify a specific window or region by providing additional arguments. For example, the command
$ scrot -s screenshot.png
captures a particular window or region you select using your mouse pointer. The -s
flag allows you to select the area to capture.
Above all, --quality
(-q)
is one of the features that fascinated me. You can use it to set the quality of the screenshot image on a scale of 1-100. For example, when I took a screenshot of a window with the quality set to 1
, I got an image size of 10.9KB (Figure 2). Whereas, when I set the quality to 100
, the file size becomes 1.0MB (Figure 3). This is particularly helpful when you have image size constraints for an application.
In addition, scrot
offers various additional options such as setting a delay before capturing, including the mouse in the capture, and using a different image format.
gnome-screenshot
On a Linux distribution with the Gnome desktop environment, gnome-screenshot
provides a feature-rich CLI for capturing screenshots [2]. To install gnome-screenshot
, use the regular apt
command (Figure 4):
$ sudo apt install gnome-screenshot
Basically, you can grab a screenshot using gnome-screenshot
by simply running the command (Figure 5):
$ gnome-screenshot -f screenshot.png
The -f
flag in Figure 5 sets the filename for the capture. By default, gnome-screenshot
captures the entire screen. Just like with scrot
, you can specify additional options to capture a specific region or window. For example, to capture a specific window, enter:
$ gnome-screenshot -w -d 3 -f screenshot.png
Here, the -w
flag sets the window to capture. With the -d
flag, you can insert a delay to the capture operation. There are also options for including the cursor in the screenshot and more.
Import
Part of the powerful ImageMagick suite, import
offers extensive capabilities for capturing screenshots from the command line [3]. ImageMagick is likely already installed on most Linux distros. If not, you can install it using the package manager specific to your distribution. For example, on Ubuntu 22.04, you can use:
$ sudo apt install imagemagick
To capture a screenshot of a specific window using import
, open a terminal and enter:
$ import screenshot.png
Next, import
asks you to select the target window using the mouse. It also allows capturing the entire X server screen using the id
or name
of the window:
$ import -window <window_id> screenshot.png
The <window_id>
attribute can be replaced with the actual identifier of the window you want to capture. Additional options provided by import
include delaying the capture, including the cursor, and output format customization.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Linux Sees Massive Performance Increase from a Single Line of Code
With one line of code, Intel was able to increase the performance of the Linux kernel by 4,000 percent.
-
Fedora KDE Approved as an Official Spin
If you prefer the Plasma desktop environment and the Fedora distribution, you're in luck because there's now an official spin that is listed on the same level as the Fedora Workstation edition.
-
New Steam Client Ups the Ante for Linux
The latest release from Steam has some pretty cool tricks up its sleeve.
-
Gnome OS Transitioning Toward a General-Purpose Distro
If you're looking for the perfectly vanilla take on the Gnome desktop, Gnome OS might be for you.
-
Fedora 41 Released with New Features
If you're a Fedora fan or just looking for a Linux distribution to help you migrate from Windows, Fedora 41 might be just the ticket.
-
AlmaLinux OS Kitten 10 Gives Power Users a Sneak Preview
If you're looking to kick the tires of AlmaLinux's upstream version, the developers have a purrfect solution.
-
Gnome 47.1 Released with a Few Fixes
The latest release of the Gnome desktop is all about fixing a few nagging issues and not about bringing new features into the mix.
-
System76 Unveils an Ampere-Powered Thelio Desktop
If you're looking for a new desktop system for developing autonomous driving and software-defined vehicle solutions. System76 has you covered.
-
VirtualBox 7.1.4 Includes Initial Support for Linux kernel 6.12
The latest version of VirtualBox has arrived and it not only adds initial support for kernel 6.12 but another feature that will make using the virtual machine tool much easier.
-
New Slimbook EVO with Raw AMD Ryzen Power
If you're looking for serious power in a 14" ultrabook that is powered by Linux, Slimbook has just the thing for you.