Taking screen captures from the command line with Scrot06 Oct 2016 | by Scott Nesbitt
Linux has some great tools for taking screen captures — tools like KSnapshot and Shutter. Even the simple utility that comes with the GNOME desktop does a pretty good job of capturing screens.
You might not need to take a screen capture all that often. Or your screen capture needs might be very simple. Or you might either be using a Linux distro without a built-in capture tool or on an older computer with limited resources.
So, what can you do? Turn to the command line and a little utility called Scrot. It does a great job of doing simple screen captures, and has a few features that might surprise you.
Getting going with Scrot
Many Linux distros come with Scrot already installed. Type which scrot to see if it’s installed. If it isn’t, you can install Scrot using your distro’s package manager. Or, if you’re willing to compile the code, grab it from GitHub.
To take a screen capture, crack open a terminal window and type:
Where [filename] is the name of file to which you want to write the image — for example, desktop.png. If you don’t include a name for the file, Scrot creates one for you like 2016-09-24-185009_1687x938_scrot.png. Not exactly descriptive, is it?
Running Scrot with no options takes a screen capture of your entire desktop. If you don’t want to do that, Scrot has an option or two you can use.
Taking a screen capture of a single window
You can tell Scrot to take a screen capture of a single window by typing:
scrot -u [filename]
The -u option tells Scrot to grab the window that’s currently in focus. That window’s usually the terminal window you’re working in. That’s not always the one you want.
To grab another window on your desktop, type:
scrot -s [filename]
The -s option lets you do one of two things:
- Select an open window, or
- Draw a rectangle around a window or a portion of a window to capture it
You can also set a delay, which gives you chance to select an open window. To do that, type:
scrot -u -d [num] [filename]
The -d option tells Scrot wait to grab the window, while [num] is the number of seconds to wait. Specifying -d 5 (wait 5 seconds) should give you enough time to choose a window.
Other useful options
Scrot has a number of other options. The ones that I find most useful are:
- -b, which also grabs the window’s border
- -t, which grabs a window and creates a thumbnail of it. This can be useful when you’re posting you screen captures online
- -c, which creates a countdown in your terminal when you use the -d option
Scrot has a number of other options, too. To be honest, I don’t use them much or at all. You might want to, though. If you do, check out the Scrot documentation by typing man scrot in a terminal window, or by reading it online.Thoughts? Let's start a conversation on Twitter.
Did you enjoy this post or find it useful? Then please consider supporting this blog with a micropayment via Liberapay. Thanks!