How to take a screenshot from the command line on Linux

Last updated on November 23, 2020 by Dan Nanni

There are various flavors of Linux screenshot utilities, including desktop-specific screenshot programs (e.g., KSnapshot for KDE, gnome-screenshot for GNOME, Screenshooter for Xfce), or general screenshot utilities (e.g., Shutter).

One of unique screenshot utilities is scrot (short for "SCReen shOT"), which is a command-line screenshot utility. While its interface is minimalistic, scrot is as powerful as other dedicated GUI-based screen capture tools feature-wise. For example, scrot supports delayed screenshot, adjustable quality/size, command line pipelining, etc. If you are one of those command line junkies, scrot is a useful tool to add to your arsenal. In this tutorial, I will describe how to take a screenshot from the command line with scrot.

Install scrot on Linux

To install scrot on Debian, Ubuntu or Linux Mint:
$ sudo apt-get install scrot

To install scrot on Fedora:

$ sudo yum install scrot

To install scrot on CentOS, you can build it from its source by first enabling Repoforge and using the following commands.

$ sudo yum install giblib-devel
$ wget http://linuxbrit.co.uk/downloads/scrot-0.8.tar.gz
$ tar xvfvz scrot-0.8.tar.gz
$ cd scrot-0.8
$ ./configure
$ make
$ sudo make install

Take Screenshots with scrot

In the rest of the tutorial, I will describe how to use scrot to take screenshots in various ways.

1. Take a screenshot of the entire desktop

It is easy to screen-capture the entire desktop. Simply run scrot command without any argument, and it will save a screenshot of the entire desktop as a (date-stamped) .png file in the current directory.

$ scrot

You can also specify a destination folder and image file name.

$ scrot ~/Pictures/my_desktop.png

2. Take a screenshot of a particular window or a rectangular region

scrot allows you to choose a specific window or define a rectangular region in your desktop to take a screenshot of. For that, use the following command.

$ scrot -s

After running this command, go ahead and click on any window or draw a rectangle with your mouse, which will trigger screen capture of the selected window/region.

Sometimes the chosen region or window may be partially blocked by other windows of the desktop. In that case, you need some time to clear the area before taking a shot. That is when delayed screenshot can help you, as described next.

3. Take a delayed screenshot

Delayed capture can be useful under various circumstances. Right before taking a shot, you may want to move windows around, activate a menu, or trigger a certain event (e.g., notification), etc. With -d N option, we can delay a screenshot process by N seconds.

$ scrot -s -d 5

4. Adjust quality of a screenshot

You can adjust the image quality of a screenshot in the range of 1 to 100 (the higher the better quality). Default quality is 75.

$ scrot -q 50

5. Adjust the size of a screenshot

You can adjust the size of a screenshot in the range of 1 to 100 (the higher the bigger). To reduce screenshot size to 10% of the original:

$ scrot -t 10

6. Pipeline a captured screenshot to another command

scrot allows you to send a saved screenshot image to any arbitrary command as an input. This option can be useful when you want to do any post-processing on a screenshot image. The filename/path of a screenshot is stored as $f string.

$ scrot -e 'mv $f ~/screenshots'

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal (Credit Card) or Bitcoin (BTC Wallet: 1M161JGAkz3oaHNvTiPFjNYkeABox8rb4g).

Xmodulo © 2020 ‒ About ‒ Powered by DigitalOcean