史上最全的使用 gnome-screenshot 获取屏幕快照指南
截屏 gnome-screenshot
在应用市场中有好几种屏幕截图工具，但其中大多数都是基于 GUI 的。如果你经常在 linux 命令行上工作，而且正在寻找一款优秀的功能丰富的基于命令行的屏幕截图工具，你可能会想尝试 [gnome-screenshot](https://linux.die.net/man/1/gnome-screenshot)。在本教程中，我将使用易于理解的例子来解释这个实用程序。


![](/data/attachment/album/201704/30/073626n0kzh0nwuaxwn0tv.jpg)


请注意，本教程中提到的所有例子已经在 Ubuntu 16.04 LTS 上测试过，测试所使用的 gonme-screenshot 版本是 3.18.0。


### 关于 Gnome-screenshot


Gnome-screenshot 是一款 GNOME 工具，顾名思义，它是一款用来对整个屏幕、一个特定的窗口或者用户所定义一些其他区域进行捕获的工具。该工具提供了几个其他的功能，包括对所捕获的截图的边界进行美化的功能。


### Gnome-screenshot 安装


Ubuntu 系统上已经预安装了 gnome-screeshot 工具，但是如果你出于某些原因需要重新安装这款软件程序，你可以使用下面的命令来进行安装：



```
sudo apt-get install gnome-screeshot

```

一旦软件安装完成后，你可以使用下面的命令来启动它：



```
gnome-screenshot

```

### Gnome-screenshot 用法/特点


在这部分，我们将讨论如何使用 gnome-screenshot ，以及它提供的所有功能。


默认情况下，使用该工具且不带任何命令行选项时，就会抓取整个屏幕。


![Starting Gnome Screenshot](/data/attachment/album/201704/30/073652qkrivxz1ixoyx9rm.png)


#### 捕获当前活动窗口


如何你需要的话，你可以使用 `-w` 选项限制到只对当前活动窗口截图。



```
gnome-screenshot -w

```

![Capturing current active window](/data/attachment/album/201704/30/073654nlllsvlaabgbtbyf.png)


#### 窗口边框


默认情况下，这个程序会将它捕获的窗口的边框包含在内，尽管还有一个明确的命令行选项 `-b` 可以启用此功能（以防你在某处想使用它）。以下是如何使用这个程序的：



```
gnome-screenshot -wb

```

当然，你需要同时使用 `-w` 选项和 `-b` 选项，以便捕获的是当前活动的窗口（否则，`-b` 将没有作用）。


更重要的是，如果你需要的话，你也可以移除窗口的边框。可以使用 `-B` 选项来完成。下面是你可以如何使用这个选项的一个例子：



```
gnome-screenshot -wB

```

下面是例子的截图：


![Window border](/data/attachment/album/201704/30/073656e41j7p9soy11aiij.png)


#### 添加效果到窗口边框


在 gnome-screenshot 工具的帮助下，您还可以向窗口边框添加各种效果。这可以使用 `--border-effect` 选项来做到。


你可以添加这款程序所提供的任何效果，比如 `shadow` 效果（在窗口添加阴影）、`bordor` 效果（在屏幕截图周围添加矩形区域）和 `vintage` 效果（使截图略微淡化，着色并在其周围添加矩形区域）。



```
gnome-screenshot --border-effect=[EFFECT]

```

例如，运行下面的命令添加 shadow 效果：



```
gnome-screenshot –border-effect=shadow

```

以下是 shadow 效果的示例快照：


![Adding effects to window borders](/data/attachment/album/201704/30/073657mxtqpo4p9tup8qqt.png)


请注意，上述屏幕截图主要集中在终端的一个角落，以便您清楚地看到阴影效果。


#### 对特定区域的截图


如何你需要，你还可以使用 gnome-screenshot 程序对你电脑屏幕的某一特定区域进行截图。这可以通过使用 `-a` 选项来完成。



```
gnome-screenshot -a
```

当上面的命令被运行后，你的鼠标指针将会变成 '+' 这个符号。在这种模式下，你可以按住鼠标左键移动鼠标来对某个特定区域截图。


这是一个示例截图，裁剪了我的终端窗口的一小部分。


![example screenshot wherein I cropped a small area of my terminal window](/data/attachment/album/201704/30/073659pqq5qqppu8s50s70.png)


#### 在截图中包含鼠标指针


默认情况下，每当你使用这个工具截图的时候，截的图中并不会包含鼠标指针。然而，这个程序是可以让你把指针包括进去的，你可以使用 `-p` 命令行选项做到。



```
gnome-screenshot -p

```

这是一个示例截图:


![Include mouse pointer in snapshot](/data/attachment/album/201704/30/073701n44qx3k1xqf01fjs.png)


#### 延时截图


截图时你还可以引入时间延迟。要做到这，你不需要给 `--delay` 选项赋予一个以秒为单位的值。



```
gnome-screenshot –delay=[SECONDS]

```

例如：



```
gnome-screenshot --delay=5

```

示例截图如下：


![Delay in taking screenshots](/data/attachment/album/201704/30/073703f2gxm09079404n2t.png)


#### 以交互模式运行这个工具


这个工具还允许你使用一个单独的 `-i` 选项来访问其所有功能。使用这个命令行选项，用户可以在运行这个命令时使用这个工具的一个或多个功能。



```
gnome-screenshot -i

```

示例截图如下：


![Run the tool in interactive mode](/data/attachment/album/201704/30/073706zzy4tipnloplpflt.png)


你可以从上面的截图中看到，`-i` 选项提供了对很多功能的访问，比如截取整个屏幕、截取当前窗口、选择一个区域进行截图、延时选项和特效选项等都在交互模式里。


#### 直接保存你的截图


如果你需要的话，你可以直接将你截的图片从终端中保存到你当前的工作目录，这意味着，在这个程序运行后，它并不要求你为截取的图片输入一个文件名。这个功能可以使用 `--file` 命令行选项来获取，很明显，需要给它传递一个文件名。



```
gnome-screenshot –file=[FILENAME]

```

例如：



```
gnome-screenshot --file=ashish

```

示例截图如下：


![Directly save your screenshot](/data/attachment/album/201704/30/073708vtog1r2gs9uds059.png)


#### 复制到剪切板


gnome-screenshot 也允许你把你截的图复制到剪切板。这可以通过使用 `-c` 命令行选项做到。



```
gnome-screenshot -c

```

![Copy to clipboard](/data/attachment/album/201704/30/073710crxgpf1ufe1op6pq.png)


在这个模式下，例如，你可以把复制的图直接粘贴到你的任何一个图片编辑器中（比如 GIMP）。


#### 多显示器情形下的截图


如果有多个显示器连接到你的系统，你想对某一个进行截图，那么你可以使用 `--then` 命令行选项。需要给这个选项一个显示器设备 ID 的值（需要被截图的显示器的 ID）。



```
gnome-screenshot --display=[DISPLAY]

```

例如：



```
gnome-screenshot --display=VGA-0

```

在上面的例子中，VAG-0 是我正试图对其进行截图的显示器的 ID。为了找到你想对其进行截图的显示器的 ID，你可以使用下面的命令：



```
xrandr --query

```

为了让你明白一些，在我的例子中这个命令产生了下面的输出：



```
$ xrandr --query
Screen 0: minimum 320 x 200, current 1366 x 768, maximum 8192 x 8192
VGA-0 connected primary 1366x768+0+0 (normal left inverted right x axis y axis) 344mm x 194mm
1366x768 59.8*+
1024x768 75.1 75.0 60.0 
832x624 74.6 
800x600 75.0 60.3 56.2 
640x480 75.0 60.0 
720x400 70.1 
HDMI-0 disconnected (normal left inverted right x axis y axis)
```

#### 自动化屏幕截图过程


正如我们之前讨论的，`-a` 命令行选项可以帮助我们对屏幕的某一个特定区域进行截图。然而，我们需要用鼠标手动选取这个区域。如果你想的话，你可以使用 gnome-screenshot 来自动化完成这个过程，但是在那种情形下，你将需要使用一个名为 `xdotol` 的工具，它可以模仿敲打键盘甚至是点击鼠标这些事件。


例如：



```
(gnome-screenshot -a &); sleep 0.1 && xdotool mousemove 100 100 mousedown 1 mousemove 400 400 mouseup 1

```

`mousemove` 子命令自动把鼠标指针定位到明确的 `X` 坐标和 `Y` 坐标的位置（上面例子中是 100 和 100）。`mousedown` 子命令触发一个与点击执行相同操作的事件（因为我们想左击，所以我们使用了参数 1），然而 `mouseup` 子命令触发一个执行用户释放鼠标按钮的任务的事件。


所以总而言之，上面所示的 `xdotool` 命令做了一项本来需要使用鼠标手动执行对同一区域进行截图的工作。特别说明，该命令把鼠标指针定位到屏幕上坐标为 `100,100` 的位置并选择封闭区域，直到指针到达屏幕上坐标为 `400,400` 的位置。所选择的区域随之被 gnome-screenshot 捕获。


这是上述命令的截图：


![screenshot of the above command](/data/attachment/album/201704/30/073712d1w8xt03ei5ev4vi.png)


这是输出的结果：


![Screenshot output](/data/attachment/album/201704/30/073713figt6uzxcx9tej38.png)


想获取更多关于 `xdotool` 的信息，[请到这来](http://manpages.ubuntu.com/manpages/trusty/man1/xdotool.1.html)。


#### 获取帮助


如果你有疑问或者你正面临一个与该命令行的其中某个选项有关的问题，那么你可以使用 --help、-？ 或者 -h 选项来获取相关信息。



```
gnome-screenshot -h

```

### 总结


我推荐你至少使用一次这个程序，因为它不仅对初学者来说比较简单，而且还提供功能丰富的高级用法体验。动起手来，尝试一下吧。




---


via: <https://www.howtoforge.com/tutorial/taking-screenshots-in-linux-using-gnome-screenshot/>


作者：[Himanshu Arora](https://www.howtoforge.com/tutorial/taking-screenshots-in-linux-using-gnome-screenshot/) 译者：[zhousiyu325](https://github.com/zhousiyu325) 校对：[jasminepeng](https://github.com/jasminepeng)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
# A comprehensive guide to taking screenshots in Linux using gnome-screenshot

### On this page

[About Gnome-screenshot](#about-gnomescreenshot)[Gnome-screenshot Installation](#gnomescreenshot-installation)[Gnome-screenshot Usage/Features](#gnomescreenshot-usagefeatures)[Capturing current active window](#capturing-current-active-window)[Window border](#window-border)[Adding effects to window borders](#adding-effects-to-window-borders)[Screenshot of a particular area](#screenshot-of-a-particular-area)[Include mouse pointer in snapshot](#include-mouse-pointer-in-snapshot)[Delay in taking screenshots](#delay-in-taking-screenshots)[Run the tool in interactive mode](#run-the-tool-in-interactive-mode)[Directly save your screenshot](#directly-save-your-screenshot)[Copy to clipboard](#copy-to-clipboard)[Screenshot in case of multiple displays](#screenshot-in-case-of-multiple-displays)[Automate the screen grabbing process](#automate-the-screen-grabbing-process)[Getting help](#getting-help)

[Conclusion](#conclusion)

There are several screenshot taking tools available in the market but most of them are GUI based. If you spend time working on the Linux command line, and are looking for a good, feature-rich command line-based screen grabbing tool, you may want to try out [gnome-screenshot](https://linux.die.net/man/1/gnome-screenshot). In this tutorial, I will explain this utility using easy to understand examples.

Please note that all the examples mentioned in this tutorial have been tested on Ubuntu 16.04 LTS, and the gnome-screenshot version we have used is 3.18.0.

## About Gnome-screenshot

Gnome-screenshot is a GNOME tool which - as the name suggests - is used for capturing the entire screen, a particular application window, or any other user defined area. The tool provides several other features, including the ability to apply beautifying effects to borders of captured screenshots.

## Gnome-screenshot Installation

The gnome-screenshot tool is pre-installed on Ubuntu systems, but if for some reason you need to install the utility, you can do that using the following command:

sudo apt-get install gnome-screenshot


Once the tool is installed, you can launch it by using following command:

gnome-screenshot

## Gnome-screenshot Usage/Features

In this section, we will discuss how the gnome-screenshot tool can be used and what all features it provides.

By default, when the tool is run without any command line options, it captures the complete screen.

### Capturing current active window

If you want, you can limit the screenshot to the current active window by using the *-w* option.

gnome-screenshot -w


Window border

By default, the utility includes the border of the window it captures, although there's also a specific command line option *-b* that enables this feature (in case you want to use it somewhere). Here's how it can be used:

gnome-screenshot -wb

Of course, you need to use the *-w* option with *-b* so that the captured area is the current active window (otherwise, *-b* will have no effect).

Moving on and more importantly, you can also remove the border of the window if you want. This can be done using the *-B* command line option. Following is an example of how you can use this option:

gnome-screenshot -wB

Here is an example snapshot:

### Adding effects to window borders

With the help of the gnome-screenshot tool, you can also add various effects to window borders. This can be done using the *--border-effect* option.

You can add any of the effects provided by the utility such as 'shadow' effect (which adds drop shadow to the window), 'border' effect (adds rectangular space around the screenshot), and 'vintage' effect (desaturating the screenshot slightly, tinting it and adding rectangular space around it).

gnome-screenshot --border-effect=[EFFECT]

For example, to add the shadow effect, run the following command

gnome-screenshot –border-effect=shadow

Here is an example snapshot of the shadow effect:

Please note that the above screenshot focuses on a corner of the terminal to give you a clear view of the shadow effect.

### Screenshot of a particular area

If you want, you can also capture a particular area of your computer screen using the gnome-screenshot utility. This can be done by using the *-a* command line option.

gnome-screenshot -a


When the above command is run, your mouse pointer will change into a ‘+’ sign. In this mode, you can grab a particular area of your screen by moving the mouse with left-click pressed.

Here is an example screenshot wherein I cropped a small area of my terminal window.


Include mouse pointer in snapshot

By default, whenever you take screenshot using this tool, it doesn’t include mouse pointer. However, the utility allows you to include the pointer, something which you can do using the *-p* command line option.

gnome-screenshot -p

Here is an example snapshot

### Delay in taking screenshots

You can also introduce time delay while taking screenshots. For this, you have to assign a value to the *--delay* option in seconds.

gnome-screenshot –delay=[SECONDS]

For example:

gnome-screenshot --delay=5

Here is an example screenshot

### Run the tool in interactive mode

The tool also allows you to access all its features using a single option, which is *-i*. Using this command line option, user can select one or more of the tool’s features at run time.

$ gnome-screenshot -i

Here is an example screenshot

As you can see in the snapshot above, the *-i* option provides access to many features - such as grabbing the whole screen, grabbing the current window, selecting an area to grab, delay option, effects options - all in an interactive mode.

### Directly save your screenshot

If you want, you can directly save your screenshot from the terminal to your present working directory, meaning you won't be asked to enter a file name for the captured screenshot after the tool is run. This feature can be accessed using the *--file* command line option which, obviously, requires a filename to be passed to it.

gnome-screenshot –file=[FILENAME]

For example:

gnome-screenshot --file=ashish

Here is an example snapshot:

### Copy to clipboard

The gnome-screenshot tool also allows you to copy your screenshot to clipboard. This can be done using the *-c* command line option.

gnome-screenshot -c

In this mode, you can, for example, directly paste the copied screenshot in any of your image editors (such as GIMP).

### Screenshot in case of multiple displays

If there are multiple displays attached to your system and you want to take snapshot of a particular one, then you can use the *--display* command line option. This option requires a value which should be the display device ID (ID of the screen being grabbed).

gnome-screenshot --display=[DISPLAY]

For example:

gnome-screenshot --display=VGA-0

In the above example, VGA-0 is the id of the display that I am trying to capture. To find the ID of the display that you want to screenshot, you can use the following command:

`xrandr --query`

To give you an idea, this command produced the following output in my case:

**$ xrandr --query**

Screen 0: minimum 320 x 200, current 1366 x 768, maximum 8192 x 8192

**VGA-0** connected primary 1366x768+0+0 (normal left inverted right x axis y axis) 344mm x 194mm

1366x768 59.8*+

1024x768 75.1 75.0 60.0

832x624 74.6

800x600 75.0 60.3 56.2

640x480 75.0 60.0

720x400 70.1

**HDMI-0** disconnected (normal left inverted right x axis y axis)

### Automate the screen grabbing process

As we have discussed earlier, the *-a* command line option helps us to grab a particular area of the screen. However, we have to select the area manually using the mouse. If you want, you can automate this process using gnome-screenshot, but in that case, you will have to use an external tool known as *xdotool*, which is capable of simulating key presses and even mouse events.

For example:

(gnome-screenshot -a &); sleep 0.1 && xdotool mousemove 100 100 mousedown 1 mousemove 400 400 mouseup 1


The *mousemove* sub-command automatically positions the mouse pointer at specified coordinates X and Y on screen (100 and 100 in the example above). The *mousedown* subcommand fires an event which performs the same operation as a click (since we wanted left-click, so we used the argument 1) , whereas the *mouseup* subcommand fires an event which performs the task of a user releasing the mouse-button.

So all in all, the xdotool command shown above does the same area-grabbing work that you otherwise have to manually do with mouse - specifically, it positions the mouse pointer to 100, 100 coordinates on the screen, selects the area enclosed until the pointer reaches 400,400 coordinates on then screen. The selected area is then captured by gnome-screenshot.

Here, is the screenshot of the above command:

And this is the output:


For more information on xdotool, head [here](http://manpages.ubuntu.com/manpages/trusty/man1/xdotool.1.html).

### Getting help

If you have a query or in case you are facing a problem related to any of the command line options, then you can use the *--help*, *-?* or *-h* options to get related information.

gnome-screenshot -h

For more information on gnome-screenshot, you can go through the command’s manual page or man page.

man gnome-screenshot

## Conclusion

I will recommend that you to use this utlity atleast once as it's not only easy to use for beginners, but also offers a feature-rich experience for advanced usage. Go ahead and give it a try.