Empower Linux Command Line With Screen Capturing Capability Through Scrot

By | 28/03/2013

I have been a Linux command line addict for many years now. Though I use Ubuntu 12.04 these days but still I spend most of the time on command line. I like to do most of my tasks through command line only. While I am pretty happy with what all I am able to do through command line but still there are few tasks for which I have to use other (GUI based) applications. One of these tasks was taking a screen-shot. I have always used graphical applications for taking screen-shots on Linux. Honestly speaking I never thought that Linux command line can be used to take a screen shot until I encountered the scrot utility.

The scrot utility can be used to take screen-shots from command line. There are various options available with this command that make this utility equally powerful and flexible as its graphical peers. In this article we will discuss some important and useful features of scrot utility through practical examples.

 

Scrot

The scrot utility does not come by default on most of the Linux distributions. You have to download it first. For example, on my Ubuntu machine, I used the following command to download scrot utility :

sudo apt-get install scrot

Once the utility is downloaded, it can be used as a command on Linux command line.  Now lets discuss in detail the usage of scrot command along with its options.

1. Scrot without any options

If you use the scrot command without any options then it will capture the complete screen in a .PNG image and save it in the current directory. The name of the file would be derived from current date and time.

Here is an example :

$ scrot
$ ls | grep *.png
2013-03-28-204412_1280x800_scrot.png

So you see that after running scrot command, a date stamped .PNG file was created in current directory.  If I open this image, it looks like :

2013-03-28-204412_1280x800_scrot (Click to enlarge)

So we see that complete screen was captured when scrot command was run without any option.

2. Select capturing area using -s option

Like any other capable screen shot utility, scrot is also capable of capturing user defined area of screen. This can be done by using -s option along with scrot command.

Here is an example :

$ scrot -s

When you hit enter after typing the above shown command, the scrot utility waits for user to select a screen area of interest using mouse. You can then select an area using your mouse and as soon as you release the mouse button, a screen shot is taken and stored as .PNG file in current directory.

Here is capture that I did using this option :

2013-03-28-210243_465x65_scrot

3. Store the output in a directory other than current directory.

As you would have observed till now, the scrot command saves the captured image in current directory. But, if a path is specified along with scrot on command prompt then this utility saves the image in that directory. Also, if you specify the name of file in the path then it even uses that name for the captured file.

Here is an example :

$ scrot /home/himanshu/Desktop/testScrot.png
$ cd /home/himanshu/Desktop
$ ls | grep test*.png
testScrot.png

So you can see that the file was stored in the specified directory and with the specified name.

4. Add delay before taking screen shot through -d option

Just like a family photograph (that includes the photographer also) , sometimes it is required to introduce a delay before taking a screen-shot on a computer. The scrot utility provides an option -d for doing the same.

For example :

$ scrot -d10

The command above would wait for 10 seconds before capturing the screen.

5. Display a countdown through -c option

If you are using a delay (-d option) then scrot provides a countdown feature through -c option. If you use -c option with -d option then a countdown is displayed during the delay session.

Here is an example :

$ scrot -cd10
Taking shot in 10.. 9.. 8.. 7.. 6.. 5.. 4.. 3.. 2.. 1.. 0.

As you can see a countdown was displayed during 10 seconds of delay.

6. Generate a thumbnail through -t option

The scrot utility also provides an option -t through which a thumbnail of captured image can be generated. This option requires an argument that specifies the percentage of the original size for the thumbnail.

Here is an example :

$ scrot -t20
$ ls
2013-03-28-220748_1280x800_scrot.png  2013-03-28-220748_256x160_scrot-thumb.png

So you can see that along with the captured image, a thumbnail (whose size is 20% of the original) was also produced.

7. Capture only the currently focused window through -u option

There are when screen is full of applications each covering small area.

For example :

2013-03-28-221425_1280x800_scrot

(Click to enlarge)

Now, in this kind of scenario, if it is required to take screen shot of a specific window rather than the whole screen then you can use the -u option provided by scrot utility.

If it is desired to take snapshot of the command prompt window the simply run the following command :

$ scrot -u

This command will capture only the command prompt window.

If it is desired to take snapshot of some other window then you can use the delay option (-d) with scrot command, run the command and during the delay focus the window (ie make the desired window your current window by clicking on it). The scrot utility will automatically take the screen shot of the focused window.

8. Open an application to display the screen shot through -e option

If you have ever used a graphical screen shot utility, you would have observed that it immediately displays the captured screen shot. The scrot utility also provides the same capability through -e option. For example, I used the following command to capture screen through scrot and display it through gimp utility.

$ scrot -e 'gimp $n'

This is a special syntax that is required to execute gimp tool with the file saved. It’s worth noting that $n represents the file-name with which the screen-shot will be saved. Instead of gimp, you can use any other tool but $n will remain same.

Just like $n, there are various other format specifiers :

$f image path/filename (ignored when used in the filename)
$n image name (ignored when used in the filename)
$s image size (bytes) (ignored when used in the filename)
$p image pixel size
$w image width
$h image height
$t image format
$$ prints a literal ‘$’

Besides displaying a screen shot using a relevant application, the -e option opens up infinite possibilities. For example, if you want to take a screen shot and store its copy to a separate directory (screenshots) then this can be done in the following way :

$ scrot -e 'cp $n ~/screenshots'

So you can see that you can do endless stuff with -e option.

Just like we discussed the some format specifiers above, there exists another category of format specifiers for year, month and day :

%Y – For year

%d – For date

%m – For month

Here is an example using these specifiers :

$ scrot '%Y-%m-%d_UbuntuLinux.png'
$ ls | grep *UbuntuLinux*
2013-03-28_UbuntuLinux.png

So we see that these format specifiers were replaced by current year, month and date respectively.

Note : To learn about some other interesting Linux commands, read our articles on netcat and strace commands.

Category: Commands Linux administration

About Himanshu Arora

Himanshu Arora is a software programmer, open source enthusiast and Linux researcher. He writes technical articles for various websites and blogs. Some of his articles have been featured on IBM developerworks, ComputerWorld and in Linux Journal. He is the administrator of the blog and also contributes useful posts on the blog. Visit his google+ profile or mail him at himanshuz.chd[at]MAILSERVER[dot]com (where MAILSERVER=gmail)

4 thoughts on “Empower Linux Command Line With Screen Capturing Capability Through Scrot

  1. chris

    “import” makes screenshots too.

    $ import -window root screen.png

    or

    $ sleep 2; import -window root screen1.png

    Reply
  2. TEMarc

    Thanks for the heads-up, turns out it was already installed. Now if I can remember it’s there to be used.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *