Screenshot tools for the command line

Say Cheese

Article from Issue 275/2023
Author(s):

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
Figure 1: Installing scrot on Ubuntu.

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.

Figure 2: A low-quality screenshot with scrot.
Figure 3: A high-quality screenshot with scrot.

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
Figure 4: Installing gnome-screenshot on Ubuntu.

Basically, you can grab a screenshot using gnome-screenshot by simply running the command (Figure 5):

$ gnome-screenshot -f screenshot.png
Figure 5: Taking a screenshot with gnome-screenshot on Ubuntu.

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

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus
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.

Learn More

News