Purpose: Every now and then, you will be find the need to take screenshots of your Linux system.  It can be either to post in a blog entry,  posting in forums and mailing list for debugging purpose, writing a tutorial, etc. This blog entry will show some methods on how to take screenshots in console, X windows system, GNOME/KDE system. People usually have a difficulty in taking screenshots in console mode.

Assumption:

While writing this entry I am running a Debian etch/stable system to be running, although this would be applicable to any Linux distro like Fedora, Ubuntu, Gentoo, etc.

Console screenshots

Method 1: (cat /dev/vcs1)

To take a screenshot of your first virtual console screen (tty1) contents  i.e. when the screen you get when you press Alt-F1 do:

# cat /dev/vcs1 > ss_console_1

To view:

# less ss_console_1

To take screenshots of your second virtual console (tty2) i.e. when you press Alt-F1 do:

# cat /dev/vcs2 > ss_console_1

For third do:

# cat /dev/vcs3 > ss_console_1

Legend:

  • /dev/ttyN – Screen Name
  • /dev/vcsN – Device Name

where ‘N’ stands for number like 1,2,3,4,…

Note: You cannot take screenshots of the a virtual console when graphics are displayed by this method. For example, if a dialog box is being displayed by the script, then you won’t be able to capture it.

Method 2: (setterm)

You can also take screenshots with setterm utility.

# apt-get update util-linux
# setterm -dump 1

This will create a file called screen.dump by default in the directory from where you gave  the above command

To view:

# less screen.dump

X Window screenshots

This section will explain how to take screenshots in your ”X’ windows system (Xorg) once you are into X windows using fluxbox or any other window managers.

Method 1: (import)

You first need to install the package imagemagick.

# apt-get update
# apt-get install imagemagick feh

This will install a utility called import.

To take screenshot of your current X windows screen do:

# import xwindow.png

Now as soon as you give this command your mouse pointer (cursor) will change into a cross-hair. Now you can either click on a specific window that is opened (say a ‘xterm’ window) or you can click on the main window (desktop) to take the screenshot of the entire screen.

To view the  image do:

# feh xwindow.png

I like to use feh to view image files when I am in fluxbox or any other light-weight window manager. There are other utilities which you can to view the file. Even the package Imagemagick has it’s own utility to view the image files. Also you can convert between different image file formats (like JPEG, TIFF, JPG, PNG, etc.) using the ‘convert‘ utility that gets installed with Imagemagick.

Method 2: (xwd)

This method might be little bit difficult and you end up getting error messages. First install the xbase-clients package:

# apt-get update
# apt-get install xbase-clients

This should install the ‘xwd’ utility.

Now to take screenshot the entire screen (desktop) do:

# xwd -root -out xwdss.xwd
# convert xwdss.xwd xwdss.png

To take screenshot of a particular window do:

# xwd -screen -out xwdss.xwd
# convert xwdss.xwd xwdss.png

You need to covert the .xwd format file into a suitable format in order to view it.

I hate to say this but please read the man page of xwd, ‘man xwd’ for further options. It is quite powerful tool although it is a bit archaic. You can connect to a remote host server and take it’s screenshot also. The option “-display” is exactly for that.

Note: It is important that you have your $DISPLAY environment set correctly, something like:
# echo $DISPLAY
:0.0
#

If it is not set correctly then you may end up getting following error message:

xwd:  unable to open display ‘ ‘

You can check if your DISPLAY variable is set correctly of not by running either:

# xhost +

or

# xwininfo
Upon running these utilities you should not see the above error message

GNOME or KDE screenshots

Taking  screenshots in full desktop environment like GNOME or KDE is very easy. There are several methods to do it:

Method 1:

Just hit the “print screen” on your keyboard and you should get a save dialog box

Method 2:

Go to GIMP->Acquire->Screenshot

Method 3:

Imagemagick method as explained above

and many more…

That’s it. Have a happy Screen-shooting….:D

Also you can use the package netpbm to convert amongst various file formats.

Hope this blog entry was useful to you.  In case if you find a better method (or a preferred one) please feel free to post a comment/feedback and I will try to cover it.

As usual, please leave a comment/feedback if you have any. Comments encourages bloggers to post more and keep their spirits high.

Also don’t forget to rate this post below.

Be Sociable, Share!