What command(s) can I use in the terminal that's equivalent to the PrtSc (Print Screen) button?
I am running Ubuntu GNOME.
69 Answers
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.pngand 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.pngTo 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 scrotTo take a screenshot in Linux from the terminal with scrot run:
scrot MyScreenshot.pngSome more options with scrot are here:
scrot -b -d 5 '%Y:%m:%d:%H:%M:%S.png' -e 'mv $f ~/Desktop/'In this example:
-bspecifies that the screenshot should include the window borders.-dspecifies 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,.pngin this case.-e 'mv $f ~/Desktop/'tellsscrotto save the screenshot on theDesktop.
Open a terminal by pressing Ctrl+Alt+T and run:
gnome-screenshotUse gnome-screenshot -d xx to delay the action. For example, to delay the screenshot action by 10 s:
gnome-screenshot -d 10or
sleep 10;gnome-screenshot 2 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 shutterTo take a screenshot of active window,
shutter -a -o shot.png -eTo take a screenshot of whole display,
shutter -f -o shot.png -eThe 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= -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. 1 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_screenshotmy_screenshot is saved under the current directory.
4I 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.pngOr, 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.pngFor the second screen only:
xwd -silent -root | convert xwd:- -crop 1920x1080+1920+0 +repage test.png 1 I'm using ubuntu 13.10 and I have a script that I just wrote which may be helpful. I see this questions been answered but my solution requires no additional installs.
#!/bin/bash
curDate=$(date)
imgExtension=".png"
imgName=$curDate$imgExtension
imgDirectory="/path/to/desires/save/directory/"
imgSavePath=$imgDirectory$imgName
gnome-screenshot --file="$imgSavePath"This code will save the screenshot without popping up the dialogue window. It uses the current time for a file name to avoid any duplicate filename issues.
No installation needed. Customized to your needs.
Place the following command in a file named
screenshot.bashanywhere you want.gnome-screenshot -a -c -f /home/<username>/Desktop/Screenshot_$(date +"%0y%0m%0d_%0H%0M%0S").pngCopy the location of this file.
Go to "Keyboard Shortcuts" and create a new one by hitting + at the end of the list
If you need just to peep into a remote computer via ssh, you can use this script.
#!/bin/bash
computer='JohnBrownsBody@10.0.0.11'
password='LiesAMoulderingInTheGrave'
path='/tmp/'
file='peepshow.png'
[ "$(whereis sshpass | cut -d: -f2)" == "" ] && sudo apt install sshpass
[ "$(whereis feh | cut -d: -f2)" == "" ] && sudo apt install feh
sshpass -p "$password" ssh $computer "export DISPLAY=:0; scrot $path$file;"
sshpass -p "$password" scp -r "$computer:$path$file" $path
# gpicview "$path$file"
feh "$path$file"
echo "... and his soul is marching on in $path$file! Peek at it!" Try this! [ Ubuntu 20.04.4 ]
# Screenshot a specific window, in this case a Firefox window:
import -window "$(wmctrl -l | cut -d ' ' -f 5- | grep -i firefox)" ~/Pictures/result.jpg# Explaining the "wmctrl -l | cut -d ' ' -f 5- | grep -i firefox", list open windows and cut out the window name part by filtering on a keyword. Install the packages if necessary!
Edit:
-Make sure you have a Firefox window open before testing!