What is the terminal command to take a screenshot?

221,742

Solution 1

Open a terminal by pressing Ctrl+Alt+T and run:

gnome-screenshot

Use gnome-screenshot -d xx to delay the action. For example, to delay the screenshot action by 10 s:

gnome-screenshot -d 10

or

sleep 10;gnome-screenshot

Solution 2

You can use the import tool available in the ImageMagick package (you need to install this if it's not already available on your system).

Then run the following command in a shell:

import screenshot.png

and select the window you want to capture or select a region by pressing the left mouse button and dragging.

import is a actually a very powerful command which can be used in many ways to capture the screen. For example, to capture the entire screen after some delay and resize it, use the following command:

import -window root -resize 400x300 -delay 200 screenshot.png

To see all the available options with the import command, go to ImageMagick’s website.


Another way to take a screenshot from the terminal is with scrot.

To install scrot run:

sudo apt-get install scrot

To take a screenshot in Linux from the terminal with scrot run:

scrot MyScreenshot.png

Some more options with scrot are here:

scrot -b -d 5 '%Y:%m:%d:%H:%M:%S.png' -e 'mv $f ~/Desktop/'

In this example:

  • -b specifies that the screenshot should include the window borders.
  • -d specifies a delay of five seconds.
  • '%Y:%m:%d:%H:%M:%S.png' will save the screenshot with a name based on the current date and time with the format specified, .png in this case.
  • -e 'mv $f ~/Desktop/' tells scrot to save the screenshot on the Desktop.

Solution 3

You can use shutter program to take screenshot from terminal.Run the below commands in terminal to install shutter,

sudo add-apt-repository ppa:shutter/ppa
sudo apt-get update
sudo apt-get install shutter

To take a screenshot of active window,

shutter -a -o shot.png -e

To take a screenshot of whole display,

shutter -f -o shot.png -e

The screenshots taken are stored in the home directory.

For more options run shutter --help command,

Usage:
    shutter [options]

Options:
    Example 1
            shutter -a -p=myprofile --min_at_startup

    Example 2
            shutter -s=100,100,300,300 -e

    Example 3
            shutter --window=.*firefox.*

    Example 4
            shutter --web=http://shutter-project.org/ -e

  Capture Mode Options:
    -s, --select=[X,Y,WIDTH,HEIGHT]
            Capture an area of the screen. Providing X,Y,WIDTH,HEIGHT is
            optional.

    -f, --full
            Capture the entire screen.

    -w, --window=[NAME_PATTERN]
            Select a window to capture. Providing a NAME_PATTERN (Perl-style
            regex) ist optional.

    -a, --active
            Capture the current active window.

    --section
            Capture a section. You will be able to select any child window
            by moving the mouse over it.

    -m, --menu
            Capture a menu.

    -t, --tooltip
            Capture a tooltip.

    --web=[URL]
            Capture a webpage. Providing an URL ist optional.

    -r, --redo
            Redo last screenshot.

  Settings Options:
    -p, --profile=NAME
            Load a specific profile on startup.

    -o, --output=FILENAME
            Specify a filename to save the screenshot to (overwrites any
            profile-related setting).

            Supported image formats: You can save to any popular image
            format (e.g. jpeg, png, gif, bmp). Additionally it is possible
            to save to pdf, ps or svg.

            Please note: There are several wildcards available, like

             %Y = year
             %m = month
             %d = day
             %T = time
             $w = width
             $h = height
             $name = multi-purpose (e.g. window title)
             $nb_name = like $name but without blanks in resulting strings
             $profile = name of current profile
             $R = random char (e.g. $RRRR = ag4r)
             %NN = counter

            The string is interpretted by strftime. See "man strftime" for
            more examples.

            As an example: shutter -f -e -o './%y-%m-%d_$w_$h.png' would
            create a file named '11-10-28_1280_800.png' in the current
            directory.

  Application Options:
    -h, --help
            Prints a brief help message and exits.

    -v, --version
            Prints version information.

    -d, --debug
            Prints a lot of debugging information to STDOUT.

    --clear_cache
            Clears cache, e.g. installed plugins, at startup.

    --min_at_startup
            Starts Shutter minimized to tray.

    --disable_systray
            Disables systray icon.

    -e, --exit_after_capture
            Exit after the first capture has been made. This is useful when
            using Shutter in scripts.

Solution 4

If you want to take a screenshot from a login-terminal (the one you open with Ctrl+Alt+F1) you can use the program fbgrab.

You can install it by typing sudo apt-get install fbcat.

Then take a screenshot of your login-terminal, type in your login-terminal:

$ sudo fbgrab my_screenshot

my_screenshot is saved under the current directory.

Solution 5

I tried using ImageMagick import but it didn't work for me when using KDE Desktop Effects. ImageMagick import has output transparent window borders in black instead of properly combining foreground alpha and background.

I also tried using X11 xwd and NetPBM xwdtopnm but that also didn't work for me, NetPBM xwdtopnm couldn't properly deal with the multiscreen output of xwd because I have a Xinerama setup.

But combining X11 xwd with ImageMagick convert worked just fine for me:

xwd -silent -root | convert xwd:- screenshot.png

Or, if you have a Dual-FullHD Xinerama setup, like me, and want the first screen only:

xwd -silent -root | convert xwd:- -crop 1920x1080+0+0 test.png

For the second screen only:

xwd -silent -root | convert xwd:- -crop 1920x1080+1920+0 +repage test.png
Share:
221,742
devav2
Author by

devav2

Full time fan of Michael Schumacher, Ferrari and F1. Ubuntu & Android enthusiast!!!

Updated on September 18, 2022

Comments

  • devav2
    devav2 over 1 year

    What command(s) can I use in the terminal that's equivalent to the PrtSc (Print Screen) button?

    I am running Ubuntu GNOME.

    • Braiam
      Braiam about 10 years
      Are you using gnome or KDE or something else? It kind of depends of what desktop environment you are using.
    • Avinash Raj
      Avinash Raj about 10 years
      @Braiam take a look at his answer.
    • Braiam
      Braiam about 10 years
      @AvinashRaj are you aware that Unity use gnome-screenshot too?
    • Avinash Raj
      Avinash Raj about 10 years
      i think gnome-screenshot is the default tool on unity for taking screenshots.
    • Ciro Santilli OurBigBook.com
      Ciro Santilli OurBigBook.com over 8 years
      Possible duplicate of What screenshot tools are available?
  • somethis
    somethis almost 11 years
    gnome-screenshot --help will give you plenty of options.
  • guneysus
    guneysus over 9 years
    Shutter is a very advanced tool that has a editing shots like GIMP and easily adding auto increment shape that is very useful for tutorials.
  • Christian Hujer
    Christian Hujer almost 9 years
    This certainly works for many users, it just didn't work for me. ImageMagick import renders KDE Desktop Effects transparent window borders / glow effect in solid black. And scrot doesn't want to participate in pipes at all, which I use to avoid unnecessary intermediate files when cropping the desired screen from a Xinerama setup. I use xwd instead and use ImageMagick convert to convert the xwd-format to PNG and do the cropping. (See also my answer below)
  • Ciro Santilli OurBigBook.com
    Ciro Santilli OurBigBook.com over 7 years
    What is the format of my_screenshot? How to view it?
  • Sylvain Leroux
    Sylvain Leroux over 7 years
    Nice answer. But since you read from pipe you probably need to specify the input format for the convert command : xwd ... | convert xwd:- .... At least it was required on my Debian Strech install with IM 6.9.6-2
  • mivk
    mivk over 6 years
    While there are many ways to make a screenshot in the GUI, this actually work in a plain console without X or any GUI. The format of the screenshot is PNG.
  • Luis Souza
    Luis Souza almost 6 years
    gnome-screenshot --interactive
  • Jack
    Jack over 3 years
    @That Brazilian Guy Every graphic command uses DISPLAY env variable to know to which X server connect. If running on ssh just export DISPLAY=:0 (or proper value) before issuing the command
  • Scooby-2
    Scooby-2 about 3 years
    Works on Ubuntu 18.04.5 server, which is the last release of the 32 bit version. This OS installs (optionally) without X, and fbcat doesn't need it. Great for writing tutorials where a tty terminal is only direct method of communication with the server and screenshots are required. +1 for this.
  • Cloud
    Cloud about 3 years
    Thank you. I was looking for this answer specifically, as it doesn't require an X-server running, and lets me take screenshots when connecting to a box via a serial port (debugging and writing tutorials). Just worth noting that the tool works great (and on Ubuntu 20.04.2 LTS x86_64) in "real shells" (i.e. via SSH, terminal access, etc.), but the output is corrupted if run within certain xterms or Guake, for example.