How to make a screenshot from the terminal/console and view it right there on Linux

Martin Dobberstein (gutschilla)
3 min readApr 14, 2020
this is a screenshot in a terminal window

The problem: I am building a Digital Signage solution using cheap Linux-running devices as player hardware and I want to roughly see what’s being shown on the monitor while being logged on via SSH.

Usually, I just want to see if the web browser I use to display content is running in fullscreen mode and not showing an error. Basically, I need a plain screenshot. But I don’t need nor want a GUI myself SSH’ing in somewhere.

Solution: scrot and viu

TL;DR=scrot+viu

Making a screenshot from the command line

Making a screenshot is fairly simple. On Debian/Ubuntu install scrot via sudo apt install scrot . To make the actual screenshot hit

DISPLAY=:0 scrot screenshot.png

You can omit DISPLAY=:0 if you’re sitting in front of you machine, the environment variable will usually be set already. Of course you can take screenshots from remote X window servers you have access to specifying a different target.

If you omit the filename scrot will use the current timestamp to name the screenshot.

Another option is DISPLAY=:0 import -window root screenshot.png if you happen to be in an environment where ImageMagick is already installed — or justsudo apt install imagemagick.

Displaying the screenshot

Of course you could download that file to your local computer via scp and use your favorite image viewer eog screenshot.png to show your remote displaying goodness.

But why not view the image as a thumbnail right in your console using some ANSI colors? All I want is to see whether that display shows some ad my customers programmed it to show or some error message. Or worse, we got hacked and are now having fresh goatse on display in all our show rooms.

Eww.. the browser ain’t in fullscreen

Anyways,

Introducing viu

Viu (https://github.com/atanunq/viu) is a very nice program written in Rust that does just that: Display a colored thumbnail of an image in your terminal. Yes, in text mode and at a horrible resolution because of that. But then again in the case of goatse that might be a good thing.

Unfortunately viu isn’t available in Debian/Ubuntu’s repositories. But the author has a precompiled binary handy: https://github.com/atanunq/viu/releases/download/v1.0/viu

The binary above is a x86–64 one. Thus, on a Raspberry Pi I had to resort to compiling from source. The Raspi sports an ARM CPU and I have no clue if and how cross-compilation in Rust works. Doubly unfortunately this requires quite a recent version of Rust (1.39) and it’s packager Cargo so you may have to get a recent Rust first. Looking at you, Raspbian!

On Ubuntu 18+ sudo apt install cargo is fine. On Raspian, use the one-liner from https://rustup.rs/ , currently

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

to install the latest Rust. And then either grab a coffee or two after issuing

cargo install viu

On a Raspberry Pi 4 compilation takes close to 5 minutes. Et voilà

viu 1.0.0 on a Raspberry Pi 4

and here we go, making a screenshot with scrot telling it to hand the filename $f over to viu immediately:

DISPLAY=:0 scrot -e 'viu $f'
The vertical display shows a somewhat black screen with a yellow headline: Good!

Neat, isn’t it?

I really use this quite often to check if things look alright on my squadron of displays.

--

--

Martin Dobberstein (gutschilla)

Roles: Web agency co-founder, Freelance consultant, Tech-Lead at a banking startup, IT Head, Solution Architect