01 May, 2010

How to take a Screenshot from the Command Line

There is no need of a graphical utility to take the screen shot of your desktop, no need to wonder how.. Lets try it with your terminal. Terminal is a powertool and solution to all the problems in linux

The advantage of using commandline tool is that if you need to take a screenshot in an environment, where you cannot run a graphical screenshot utility prefer this method.

1. Take a Screenshot from an X Terminal

Take the gnome terminal and type in as follows

   $ sleep 5; import -window root screen.png   
                       
                        The sleep command delays the process for five seconds before the screenshot is taken. This is the time to minimize windows, expand menus, or make other necessary adjustments before the screenshot is taken. By changing the sleep value you can control the delay before the screenshot is taken.                         

                        The import utility that is part of the ImageMagick suite of tools to take a screenshot of the entire window and name the image screen.png. If you want to grab a particular part of the screen, you also can use the -crop option to grab that specific area

                      $import -crop 500x400                  

And if you run import without -window your cursor will change to a crosshair, which you can drag over the area you want to capture. PNG is a recommended screenshot format, but ImageMagick supports a range of different formats, so you can use what you need. Type as below to see the man page to know more about import.

                            $ man import                              


2. Take a Screenshot from a Command-Line Terminal

               If you need to take a screenshot from a command-line console while X is running elsewhere on the system, adjust the command line and add a few additional features to it. This method is commonly used when you need a screenshot of an installation routine or a program running on an embedded device.To do this, first access the shell that runs behind the installer by pressing Ctrl-Alt-F3.This terminal is called tty3. It provides you with a simple shell in which you can run the commands to grab the shot.

                       Before you can run the command to grab the shot, find out the display number of the running X server. Every X server has a unique display number that is mapped to the particular user who is using X. You can find this by typing in the  terminal as follows

                        $ echo $DISPLAY                            

Let your display number returns :0.0, Then the command to grab the screenshot is:

 $ chvt 7; sleep 5; import -window root screen.png -display :0.0 ; chvt 3  

Three actions will take place following to this,

process of switching to the X terminal
grabbing the screenshot
switching back to your current command-line terminal.


The first command (chvt 7) switches to the X terminal say gnome (usually the 7th terminal is the X), and then the second command (sleep 5) pauses the process for two seconds to switch to the 7th terminal. Then the import command is used to grab the root window on display :0.0 and save the shot as screen.png. Finally, the terminal is switched back to terminal 2 (chvt 2).

You can change the virtual terminal by changing the number after the chvt.

1 comments:

Anonymous said...

Another option is to use xwd which is a standard X tool and more likely to be present. Then again, you'll most likely require ImageMagick to convert the screenshot to a suitable format anyway. lol.

Post a Comment

speak out... itz your time !!!

 

Terminal Diary | techblog Copyright © 2009 Gadget Blog is Designed by jintu jacob Powered by Blogger