How To Take Screenshots From Command Line Using “Scrot” In Linux
There is a saying – “A picture is worth a thousand words”. In fact, a Picture speaks louder than words. Be it a documentation work, technical writing, blogging or all sorts of writing jobs, screenshots are very very important. No one will believe you if you don’t attach relevant screenshots in your articles. I use Shutter, a very great GUI screenshot tool for taking and editing screenshots. Once I settled with Shutter, I never searched for the another tool. It has all options that I need for my Job. However, today, in the pursuit of finding command-line alternatives for most Graphical user interface tools, I came across “Scrot”. It is a command-line screenshot tool for taking screenshots in Unix-like operating systems. Scrot (acronym for SCReenshOT) is a simple, lightweight command line screenshot tool that uses imlib2 library to capture screenshots in Unix-like operating systems. It is developed by Tom Gilbert, and is written using C programming language.
Without further ado, I gave it a try. I must admit that it is one of the useful CLI utilities. I dug a little bit deeper and learned some quick tricks to take screenshots from command line using scrot. In this tutorial, I will show how to install and use scrot in Unix-like operating systems.
Take Screenshots From Command Line Using Scrot In Linux
Scrot comes pre-installed in most Linux distributions. Just in case, if it is not installed already, you can install it using your distribution’s default package manager.
In Arch Linux and derivatives:
$ sudo pacman -S scrot
$ sudo dnf install scrot
On RHEL, CentOS:
$ sudo yum install scrot
In Debian, Ubuntu, Linux Mint:
$ sudo apt-get install scrot
In SUSE, openSUSE:
$ sudo zypper in scrot
They typical usage of scrot command is:
$ scrot [options] [file]
Capture whole screen
When you run the scrot command without any additional options, it will capture the whole screen.
Sample output of my whole desktop.
The captured images will be saved in the current directory with a date-stamped filename (Ex. 2017-05-08-172226_1366x768_scrot.png) by default. All images will be saved in PNG format.
To capture and save the screenshot with a name of your choice, use:
$ scrot image-name.png
Also, you can save the captured image to any location of your choice.
$ scrot /home/sk/Downloads/test.jpg
The above command will capture the whole screen and save it in /home/sk/Downloads/ directory with name test.jpg. Please note that I have saved it with .jpg extension. That means, we can save the images in different image formats too.
Capture current window
Instead of capturing the whole screen, you can take the screenshot a currently focused window. To take screenshot of the current window, run:
$ scrot -u
See? Scrot now captured the currently focused (i.e current window) window, which is the Terminal window itself.
Capture particular window
To interactively select a window or rectangle with the mouse, use -s flag as shown below.
Look at the following image. This image has three opened windows.
I don’t want to capture all of them. I only want to capture the SMPlayer window.
To do so, I ran the following command and clicked on the SMPlayer window.
$ scrot -s
Here is the screenshot after clicking on the SMPlayer window.
Include window border in screenshots
As you may noticed in “Capture current window” section, there was no border. You can include window border in screenshots using -ub option like below.
$ scrot -ub
- -u – focused window (current window)
- -b – include broder
Have a look at the following examples.
Without window border (scrot -u):
With Window border (scrot -ub):
Delay while taking screenshots
Some times you may want to wait X seconds before taking a screenshot. If so, use -d flag like below.
$ scrot -d 5
$ scrot --delay 5
The above command will capture the screenshot after 5 seconds.
You can also display countdown time when used with delay using -c or –count flag.
$ scrot -u -d 5 -c
The above command will capture the current window after 5 seconds and display the countdown time while taking screenshot.
Generate image thumbnails
Sometimes, you might want to create a thumbnail of the screenshot. Well, scrot has an option for that too.
To generate a thumbnail for the image, use -t flag like below.
$ scrot -t 50
Here, 50 is the percentage of the original size for the thumbnail to be. Let us say, your original screenshot size is 1366×768, then the thumbnail size would be around 683×384 (i.e half size of the original screenshot).
Scrot will save the original and thumbnail of the original in the current directory.
Set Image quality
Another notable feature of the Scrot is it will allow you to set the image quality to the captured images. The default image quality is 75. Also, Image effect differs depending on file format chosen. We can adjust the Image quality at the scale of 1-100. High value means high size, low compression
The following command will capture the current window, and set the image quality to 20.
$ scrot -u -q 20
You can edit the captured images using any image editor, for example Gimp, using command:
$ scrot test.png -e 'gimp test.png'
The above command will open test.png image in GIMP. Make sure you have installed GIMP.
Edit the image as per your liking in GIMP, and save it either with same name or different name.
For more details, I suggest you to refer the man pages.
$ man scrot
And, that’s all. You know now how to install and use scrot for taking screenshots from the command line in your Linux box.
If you find our guides useful, please share them on your social, professional networks and support OSTechNix. More good stuffs to come. Stay tuned!
Thanks for stopping by!
Help us to help you:
- Subscribe to our Email Newsletter : Sign Up Now
- Support OSTechNix : Donate Via PayPal
- Download free E-Books and Videos : OSTechNix on TradePub
- Connect with us: Facebook | Twitter | Google Plus | LinkedIn | RSS feeds
Have a Good day!!