How to use commands to take screenshots in Linux graphical interface


Previously, in Linux, the screenshots were all by pressing the print screen key or Alt + print screen.

But print screen is the whole screen, ALT + print screen is the current window.

What do you want to use to capture an area on the screen?

The answer is the Import command

Copy code

The code is as follows:

$ import ddd.jpg

Then the mouse will become “+”, just like QQ’s screenshot tool, a drag OK, very convenient.

Screenshot of login interface

In daily use, our screenshot operations are carried out after logging in to the system, such as capturing a window, capturing a specified area, or capturing the whole web page. To get a screenshot of the login interface, it is necessary to do the operation before login, which is a bit complicated.
Under the root permission, use these commands to capture a screenshot of the login interface:

Copy code

The code is as follows:

chvt 8
sleep 5
DISPLAY=:0.0 XAUTHORITY=/var/lib/mdm/:0.Xauth xwd -root > /tmp/shot.xwd
convert /tmp/shot.xwd /tmp/ss.png

The most critical part of these commands is xauthority = / var / lib / MDM / in the third line. Different distributions use different login managers by default. For example, Ubuntu uses lightdm, Kubuntu uses KDM, Linux Mint uses MDM, and gnome uses GDM.

Different login managers have different xauthority. So some of the materials found on the Internet are xauthority = / var / run / lightdm / root /, and some are xauthority = / var / lib / GDM /. So the question is, how can we determine which login manager is used in the current system?

Of course, you can’t slap your head. You have to be reasonable. At the beginning, I used to think that the DM I was using was KDM. As a result, I fell into the pit.

In fact, it’s very simple. Just take a look at the process whose name contains DM, and you can determine how to write the command.