how to take screenshot in ubuntu terminal

Taking screenshots directly from the terminal in Ubuntu can be a convenient and efficient method, especially for users who work primarily in the command line. Unlike traditional methods that involve graphical tools, terminal-based screenshot options offer more flexibility and automation capabilities. By using a few simple commands, users can capture their screen, specific windows, or defined areas and save these screenshots directly to a specified location. This approach is particularly useful for scripting automated screenshots or documenting terminal-based workflows. In this guide, we will explore various command-line tools that make capturing screenshots in Ubuntu a straightforward task.

Using the gnome-screenshot Command

The gnome-screenshot command is a simple and powerful tool available in many Ubuntu distributions. It allows users to capture screenshots directly from the terminal without needing a graphical interface. This tool can be useful for capturing the entire screen, specific windows, or selected areas, and offers options for saving screenshots automatically.

1. Installing gnome-screenshot (if not already available)
In many cases, gnome-screenshot is pre-installed on Ubuntu. If it’s not available, you can install it by running:

sudo apt update
sudo apt install gnome-screenshot

2. Basic Usage of gnome-screenshot
To take a full-screen screenshot and save it in the default pictures folder, simply enter:

gnome-screenshot

3. Capturing Specific Windows with gnome-screenshot
To capture a specific window, use the -w option. This command will let you select a window by clicking on it:

gnome-screenshot -w

4. Delaying the Screenshot
You can add a delay (in seconds) before capturing the screenshot using the -d option. For example, to capture a screenshot after a 5-second delay, use:

gnome-screenshot -d 5

5. Saving the Screenshot to a Custom Location
You can specify the save location with the -f option, followed by the file path. For example:

gnome-screenshot -f ~/Desktop/my_screenshot.png

These options make gnome-screenshot a versatile tool for taking screenshots directly from the terminal with various customizations.

Using the scrot Command for Screenshots

The scrot command is another popular tool for taking screenshots directly from the terminal. It’s lightweight, easy to use, and offers various options for capturing the screen with customizations such as delays, file naming, and specific areas.

1. Installing scrot
If scrot is not already installed, you can add it to your system by running:

sudo apt update
sudo apt install scrot

2. Capturing the Full Screen
To capture the entire screen and save it to the default folder, use the simple command:

scrot

3. Delayed Capture with scrot
To set a delay (in seconds) before capturing the screenshot, use the -d option. For example, to wait 5 seconds:

scrot -d 5

4. Specifying File Name and Location
You can specify a custom name and location for your screenshot using the following syntax:

scrot ~/Desktop/custom_screenshot.png

5. Capturing a Specific Area
The scrot command also allows you to capture a specific area of the screen by using the -s option, where you can select an area with your mouse:

scrot -s

The flexibility of scrot makes it a great tool for capturing screenshots with different customizations from the Ubuntu terminal.

Taking Screenshots with the import Command (ImageMagick)

The import command from the ImageMagick suite is a powerful tool for taking screenshots from the terminal. It allows for capturing the full screen, specific windows, or defined areas, and offers advanced features for users familiar with ImageMagick’s image processing capabilities.

1. Installing ImageMagick
If ImageMagick is not installed on your system, you can install it by running:

sudo apt update
sudo apt install imagemagick

2. Capturing the Full Screen
To take a screenshot of the entire screen and save it, use:

import -window root full_screenshot.png

3. Capturing a Specific Window
The import command allows you to capture a specific window by clicking on it. Run the following command, then click on the desired window:

import window_screenshot.png

4. Capturing a Selected Area
To capture a specific area, you can use the following command and then drag to select the area:

import area_screenshot.png

5. Adding Delay Before Capture
To add a delay before capturing the screenshot, use the sleep command. For example, to wait 5 seconds:

sleep 5; import -window root delayed_screenshot.png

The import command, combined with the capabilities of ImageMagick, makes it a versatile option for capturing and editing screenshots in Ubuntu.

Using xfce4-screenshooter for Screenshots

The xfce4-screenshooter tool is commonly used in the XFCE desktop environment, but it can also be installed and used on other desktop environments in Ubuntu. It’s a straightforward tool with various options for capturing the entire screen, specific windows, or selected areas, and includes a user-friendly interface for saving and managing screenshots.

1. Installing xfce4-screenshooter
If xfce4-screenshooter is not already installed on your system, you can install it with:

sudo apt update
sudo apt install xfce4-screenshooter

2. Capturing the Entire Screen
To capture the entire screen, simply use the following command:

xfce4-screenshooter -f

3. Capturing a Specific Window
To capture a specific window, use the -w option. This command will let you select the desired window for capturing:

xfce4-screenshooter -w

4. Capturing a Selected Area
For capturing a specific area, use the -r option, allowing you to drag and select the area you want to capture:

xfce4-screenshooter -r

5. Delayed Screenshot Capture
To add a delay before taking the screenshot, use the -d option followed by the number of seconds. For example, to delay by 5 seconds:

xfce4-screenshooter -d 5 -f

6. Opening Screenshot with an Editor
You can automatically open the screenshot in an editor after capturing by adding the -o option:

xfce4-screenshooter -o

The xfce4-screenshooter command is a versatile and simple tool, ideal for quick screenshots and easy customization from the Ubuntu terminal.

Taking Screenshots Using screen and script Commands

The screen and script commands are not traditional screenshot tools but are effective for capturing terminal output in a text format. This can be useful for recording terminal sessions, logging commands, and saving terminal activities for documentation. Though they don’t capture visual screenshots, they can be used to capture output, which can later be converted into an image if needed.

1. Using script to Record Terminal Output
The script command records everything typed in the terminal, including output, and saves it to a text file. This can be useful for creating text-based logs of terminal activities.

script terminal_log.txt

After running the above command, all terminal activity is saved to terminal_log.txt until you type exit to end the recording.

2. Using screen to Capture Terminal Sessions
The screen command allows users to manage multiple terminal sessions and can save logs of these sessions. To start a session with logging enabled, use:

screen -L

This will log the session output in a file named screenlog.0 by default. To end the session, simply type exit or detach with Ctrl+A followed by D.

3. Converting Text Output to an Image
Once you have a text log from script or screen, you can convert it to an image using tools like convert from ImageMagick:

convert -background white -fill black -font Courier -pointsize 12 label:@terminal_log.txt output_image.png

This command converts the contents of terminal_log.txt into a PNG image.

4. Automating Session Logging with a Shell Script
You can create a shell script to automate the logging process. Here’s an example script:

#!/bin/bash
script -c "your_command" log.txt
convert -background white -fill black -font Courier -pointsize 12 label:@log.txt output_image.png

This script records the command output into log.txt and converts it to an image named output_image.png.

These methods are ideal for documentation and logging purposes rather than traditional visual screenshots.

Saving and Accessing Screenshots in Ubuntu

Ubuntu provides multiple options for saving and accessing screenshots. After capturing a screenshot using various tools, you can choose to save it to a specific folder or location for easy access and organization. Here are some of the common ways to manage screenshot files in Ubuntu.

1. Default Save Location
Most screenshot tools, such as gnome-screenshot, scrot, and xfce4-screenshooter, save screenshots to the default “Pictures” directory. You can access this folder by opening the file manager and navigating to:

~/Pictures

2. Specifying a Custom Save Path
If you prefer to save screenshots in a different location, you can specify a custom path in the command. For example:

scrot ~/Desktop/custom_screenshot.png

This command saves the screenshot to the Desktop with the name custom_screenshot.png.

3. Organizing Screenshots by Date and Time
To organize screenshots efficiently, you can save files with timestamps. Using scrot or other commands, you can add the current date and time to the filename like this:

scrot ~/Pictures/screenshot_%Y-%m-%d_%H-%M-%S.png

This saves the screenshot with a unique name based on the date and time, such as screenshot_2024-11-09_12-30-00.png.

4. Accessing Screenshots Quickly Using File Manager Shortcuts
In Ubuntu, the file manager provides shortcuts to frequently accessed folders, including the “Pictures” folder. You can open the file manager with:

nautilus ~/Pictures

5. Syncing Screenshots to Cloud Storage
To ensure screenshots are accessible from multiple devices, you can sync your “Pictures” or any other custom screenshot folder with cloud services like Dropbox or Google Drive. This can be set up by linking the folder to the cloud storage folder, making your screenshots available on all synced devices.

These methods make it easy to manage, organize, and access screenshots effectively on Ubuntu.

Conclusion

Capturing and managing screenshots in Ubuntu through terminal commands offers both flexibility and efficiency, especially for users who prefer working in a command-line environment. Tools like gnome-screenshot, scrot, import, and xfce4-screenshooter each provide unique functionalities tailored to different needs—whether it’s capturing the entire screen, specific windows, or selected areas. Additionally, commands such as script and screen are valuable for recording terminal output in text form, which can later be converted to image formats for documentation purposes.

By learning and mastering these tools, users can quickly create, organize, and access screenshots directly from the terminal, streamlining workflows and reducing dependency on GUI applications. Furthermore, custom save paths, timestamped file names, and cloud syncing options enhance the accessibility and organization of screenshots, making them easily retrievable whenever needed. Ultimately, Ubuntu provides a powerful set of options for managing screenshots effectively in both GUI and command-line interfaces.

Share:

More Posts

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments