Linux tip: How to take a screenshot without X (GUI), just from console

By Detector | 09 January 2009

There are lot of screen-capture tools, but a lot of them are based on X(GUI). Sometimes, when running an X application may interfere with the application you wanted to grab – perhaps a game or even a Linux installer. If you use the venerable ImageMagick import command though, you can grab from an X session via the console(terminal). Simply go to a virtual terminal (Ctrl+Alt+F1 for example) and enter the following:

chvt 7; sleep 2; import -display :0.0 -window root sshot1.png; chvt 1;

The chvt command changes the virtual terminal, and the sleep command gives it a while to redraw the screen. The import command then captures the whole display and saves it to a file before the final chvt command sticks you back in the virtual terminal again. Make sure you type the whole command on one line.

This can even work on Linux installers, many of which leave a console running in the background – just load up a floppy/CD with import and the few libraries it requires for a first-rate run-anywhere screen grabber.

Tags | , ,

| |

6 Responses to “Linux tip: How to take a screenshot without X (GUI), just from console”

  1. Anonymous says:

    i guess you cold as well use this strategy in a script to make screencasts of CLI sessions!

  2. Anonymous says:

    No, this captures X sessions only. The “chvt 7″ changes to virtual console number 7, which traditionally has X running on it on most Linux distributions.

    If you want to capture command line sessions, try “script”.

    As an aside, since import takes the display as an argument, do you even need to use chvt at all?

  3. Robert says:

    Hi anonymous, I think that the idea of this tip is to capture X on most of Linux distributions from another virtual console. This tip will work also with another virtual console (not just 7).


  4. Anonymous says:

    The title, "How to take a screenshot without X . . .", is very misleading. You need to be running X because the the utility called by the script, import, requires X.

    Frrom the man page:

    import – saves any visible window on an X server and outputs it as an image file.

    Sure, you can start it from a VT, but without an X server running you will have nothing to capture. It will not capture a virtual terminal that has no X server.

  5. You really help it become seem really easy with your demonstration but I find this specific topic being really an issue that I think I’d never understand. It seems way too complicated and incredibly broad for me personally. I am looking forward for your next publish, I will try to get the practice it!


Add to Technorati Favorites
website stats
TwitterCounter for @ukion