Linux

Scrot Command Line Screen Capture on Linux

Scrot Command Line Screen Capture

In this tutorial, we will show you learn about Scrot Command Line Screen Capture on Linux. Taking screenshots in Linux doesn’t always require fancy graphical tools. Sometimes the most powerful screen capture solution is a simple command-line utility. Scrot (SCReenshOT) is precisely that—a lightweight yet versatile screenshot tool that brings efficiency and flexibility to your Linux workflow. Whether you’re a system administrator documenting configurations, a developer reporting bugs, or simply a Linux enthusiast who prefers terminal-based solutions, mastering Scrot can significantly streamline your screenshot process.

Introduction

Scrot is a minimalist command-line screenshot utility designed specifically for Linux systems. It provides a clean, efficient way to capture screen content without the overhead of graphical interfaces. Despite its simplicity, Scrot offers remarkable flexibility for capturing anything from full-screen images to specific windows and custom selections.

The name “Scrot” derives from “SCReenshOT,” following the Unix tradition of abbreviated command names. This lightweight tool relies on the imlib2 library for capturing and saving images, making it highly efficient on systems with limited resources.

For Linux users who value speed, automation capabilities, and script integration, Scrot presents distinct advantages over GUI-based alternatives. Its command-line nature means you can easily incorporate it into scripts, cron jobs, and other automated workflows—something that’s more cumbersome with graphical tools.

Understanding Scrot Fundamentals

Scrot is built on a foundation of simplicity and efficiency, designed to provide powerful screenshot functionality with minimal system impact. At its core, Scrot leverages the imlib2 graphics library, which handles the image capture and processing tasks.

Technical Foundation

The utility supports multiple image formats including PNG, JPG, and GIF, allowing you to choose the best format for your specific needs. PNG is ideal for screenshots with text or sharp edges, while JPG might be preferable when file size is a concern.

Scrot’s system requirements are minimal, making it suitable for older hardware and lightweight Linux distributions. It works seamlessly with various window managers and desktop environments, providing consistent functionality regardless of your setup.

Design Philosophy

Scrot’s design follows the Unix philosophy of doing one thing well. Rather than trying to be an all-encompassing screenshot solution with editing features, Scrot focuses exclusively on capturing screens efficiently. This specialization allows for better performance and easier integration with other tools in your workflow.

The command structure remains intuitive and consistent, making it accessible to users with even basic command-line experience. This simplicity doesn’t compromise functionality—Scrot offers numerous capture options through straightforward command-line parameters.

Installation Process

Before you can start using Scrot, you’ll need to install it on your Linux system. The process varies slightly depending on your distribution, but it’s generally straightforward.

First, check if Scrot is already installed on your system by running:

which scrot

If the command returns a path, Scrot is already installed. If not, you’ll need to install it using your distribution’s package manager.

Debian/Ubuntu/Mint

For Debian-based distributions, use the apt package manager:

sudo apt update
sudo apt install scrot

RHEL/CentOS/Fedora

For Red Hat-based distributions, use yum or dnf:

sudo yum install scrot

Or for newer Fedora versions:

sudo dnf install scrot

Arch Linux

For Arch Linux and derivatives:

sudo pacman -S scrot

Installing from Source

If you prefer to install from source or need the latest version, you can clone the repository from GitHub and compile it:

git clone https://github.com/resurrecting-open-source-projects/scrot.git
cd scrot
./autogen.sh
./configure
make
sudo make install

After installation, verify that Scrot is working correctly by running:

scrot -v

This should display the version information, confirming a successful installation.

Basic Screenshot Capture

Taking a full-screen screenshot with Scrot is remarkably simple. The most basic command requires no additional parameters:

scrot

When executed without any options, this command captures your entire screen and saves it in the current working directory. By default, Scrot generates a filename based on the current date, time, and screen resolution, resulting in something like 2025-06-17-220943_1920x1080_scrot.png.

Custom Filenames

While the default naming works, you’ll often want to specify your own filename for better organization:

scrot mydesktop.png

This captures the full screen and saves it as “mydesktop.png” in your current directory. You can include a full path to save screenshots in a specific location:

scrot /home/username/Screenshots/capture.png

Output Format

Scrot supports various image formats, including PNG, JPG, and GIF. Simply specify the desired format in the filename extension:

scrot desktop.jpg

Common Issues

If you encounter permission errors when saving screenshots, ensure you have write permissions for the target directory. When using Scrot in a script or cron job, remember that the environment might differ from your interactive shell, potentially affecting the save location.

Capturing Specific Windows

Sometimes you need to capture just a single window rather than the entire screen. Scrot offers several options for window-specific captures.

Capturing the Active Window

To capture only the currently focused window, use the -u flag:

scrot -u window.png

This command captures the window that currently has focus—typically the terminal where you’re running the command. To capture a different window, you’ll need to combine this with a delay.

Delayed Window Capture

To capture a specific window that isn’t currently in focus:

scrot -u -d 5 window.png

The -d 5 flag adds a 5-second delay, giving you time to click on and focus the window you want to capture before the screenshot is taken.

Interactive Window Selection

For more precise control, use the -s flag to select a window interactively:

scrot -s window.png

After executing this command, your cursor will change, allowing you to click on any window to capture it. This is particularly useful when you need to capture a specific application or dialog box.

Including Window Borders

By default, Scrot might not capture window borders in some environments. To ensure borders are included, add the -b option:

scrot -u -b window_with_border.png

This is especially useful when documenting window appearance or creating tutorials that reference window decorations.

Selection and Region Capture

When you need to capture a specific portion of your screen rather than a complete window, Scrot’s selection mode becomes invaluable.

Interactive Selection

To capture a custom region, use the -s option:

scrot -s region.png

After executing this command, click and drag your mouse to draw a rectangle around the area you want to capture. When you release the mouse button, Scrot will capture the selected region.

Selection Tips

For precise selections, it helps to:

  • Start from a corner of the content you want to capture
  • Use the crosshair cursor as a guide for alignment
  • Hold Shift while drawing to maintain square proportions
  • Take your time—the selection doesn’t time out

Common Selection Challenges

Sometimes selecting regions can be tricky, especially with certain desktop environments. If you’re having trouble with selection mode:

  1. Ensure you have the right permissions
  2. Try adding a small delay with -d 1 to give the system time to switch to selection mode
  3. Consider using line style options for better visibility during selection

Line Style Options

You can customize the appearance of selection lines with the -l option followed by a style parameter:

scrot -s -l style region.png

This makes the selection boundary more visible, which is helpful in displays with high contrast or when capturing areas with similar colors.

Delayed Screenshots

Timing is often crucial when taking screenshots, especially when you need to capture menus, tooltips, or other transient elements. Scrot’s delay options give you precise control over when the capture occurs.

Basic Delay

To add a simple delay before capturing:

scrot -d 5 delayed.png

This command waits 5 seconds before taking the screenshot, giving you time to set up the screen exactly as needed.

Countdown Timer

For visual feedback during the delay, add the -c option:

scrot -d 10 -c countdown.png

This displays a countdown in the terminal, helping you time your actions perfectly.

Combining Delay with Other Options

Delays work well with other capture modes:

scrot -s -d 3 -c selection_after_delay.png

This gives you 3 seconds to prepare before entering selection mode.

Practical Delay Examples

  • Capture dropdown menus: scrot -d 2 menu.png
  • Take screenshot during application startup: scrot -d 5 startup.png
  • Capture tooltip text: scrot -s -d 3 tooltip.png
  • Record a sequence at regular intervals: scrot -d 5 sequence_%Y-%m-%d_%H:%M:%S.png

The delay feature is particularly useful for capturing dynamic content that requires some interaction to display.

File Management Options

Scrot provides extensive options for managing the output files, allowing you to create organized and meaningful screenshot collections.

Custom Naming Formats

One of Scrot’s most powerful features is its support for timestamp variables in filenames:

scrot '%Y-%m-%d_%H-%M-%S.png'

This creates files named with the current date and time in YYYY-MM-DD_HH-MM-SS format. Available time format specifiers follow the standard strftime syntax.

Adding Context to Filenames

You can combine fixed text with time variables:

scrot 'desktop_%Y%m%d_%H%M%S.png'

Or include system information:

scrot '%h_%wx%h.png'

This includes the hostname and screen dimensions in the filename.

Directory Specification

Explicitly set the save location with a full path:

scrot ~/Screenshots/%Y/%m/%d/capture.png

This example organizes screenshots in a year/month/day folder structure.

Quality Settings

For JPEG images, you can specify the compression quality:

scrot -q 75 compressed.jpg

The -q option accepts values from 1 (lowest quality, smallest file) to 100 (highest quality, largest file). For everyday screenshots, a value between 75 and 85 usually offers a good balance.

File Size Considerations

When disk space is a concern:

  • Use JPG format for photographic content
  • Reduce quality settings for JPG images
  • Use PNG for text-heavy screenshots where quality is critical
  • Consider automatic thumbnail generation for quick references

Creating Thumbnails

Thumbnails are useful when you need smaller reference images alongside full-resolution screenshots. Scrot can generate these automatically.

Basic Thumbnail Generation

To create a thumbnail alongside the main screenshot:

scrot -t 50 with_thumb.png

This command captures the screen and creates a thumbnail at 50% of the original size. The thumbnail will be saved with “_thumb” appended to the filename.

Custom Thumbnail Sizes

You can specify different percentage sizes:

scrot -t 25 small_thumb.png

This creates a thumbnail at 25% of the original dimensions.

Combining with Other Options

Thumbnails work with all capture modes:

scrot -s -t 20 window_with_thumb.png

This creates a thumbnail of your selected region.

Practical Applications

Thumbnails are particularly useful for:

  • Creating documentation with preview images
  • Web galleries of screenshots
  • Quick reference collections
  • Saving disk space while maintaining access to full-resolution images when needed

The thumbnail feature eliminates the need for separate image processing steps, streamlining your workflow.

Automating Screenshots with Cron

One of Scrot’s major advantages is its ability to be automated using cron jobs, enabling scheduled screenshots for monitoring, documentation, or security purposes.

Basic Crontab Setup

To set up automated screenshots, edit your crontab:

crontab -e

Then add an entry to take screenshots at specific intervals:

# Take screenshot every hour
0 * * * * scrot /home/user/monitoring/%Y-%m-%d_%H-%M.png

Environment Considerations

When running Scrot through cron, remember:

  • Cron runs with a limited environment; you may need to specify the full path to the scrot executable
  • The DISPLAY variable must be set for screen captures to work
  • File permissions and ownership need to be considered

A more complete cron entry might look like:

0 * * * * DISPLAY=:0 /usr/bin/scrot /home/user/monitoring/%Y-%m-%d_%H-%M.png

Organizing Automated Captures

To prevent filling your disk with screenshots, consider:

  • Using a cleanup script to delete old captures
  • Implementing a rotating log system
  • Using date-based directories to organize files

Troubleshooting Automation

If your cron job isn’t capturing screenshots:

  1. Check cron logs for errors: grep CRON /var/log/syslog
  2. Test the command manually with the same environment variables
  3. Verify the display is accessible to the user running the cron job
  4. Ensure the save directory exists and has proper permissions

Advanced Command Options

Beyond the basic functionality, Scrot offers several advanced options that provide even greater control and flexibility.

Executing Commands on Captures

One of Scrot’s most powerful features is the ability to execute commands on the captured image:

scrot -e 'mv $f ~/Screenshots/ && gimp ~/Screenshots/$f'

This captures the screen, moves the file to ~/Screenshots/, and then opens it in GIMP. The $f variable represents the filename of the captured image.

Multi-monitor Handling

When working with multiple displays, use the -m option:

scrot -m multiscreen.png

This ensures that all connected displays are captured in order.

Working with Display Environment Variables

You can specify which display to capture:

DISPLAY=:0.1 scrot secondary_monitor.png

This targets a specific display when multiple are present.

Piping Scrot Output

Combine Scrot with other commands using pipes:

scrot - | convert - -crop 800x600+100+100 cropped.png

The dash parameter outputs to stdout, allowing you to pipe the image data to other tools like ImageMagick.

Creative Command Combinations

scrot -cd 5 -q 85 -t 20 '%Y-%m-%d_$wx$h.jpg' -e 'mogrify -modulate 120 $f && mv $f ~/shots/'

This complex command:

  • Adds a 5-second countdown
  • Sets JPEG quality to 85%
  • Creates a 20% thumbnail
  • Uses a custom filename with date and dimensions
  • Applies brightness enhancement using mogrify
  • Moves the result to the ~/shots directory

Integrating Scrot with Scripts

Scrot truly shines when integrated into shell scripts for more complex screenshot automation.

Basic Bash Script

Here’s a simple script that takes timestamped screenshots:

#!/bin/bash

OUTPUT_DIR="$HOME/Screenshots"
mkdir -p "$OUTPUT_DIR"

TIMESTAMP=$(date +%Y%m%d_%H%M%S)
scrot "$OUTPUT_DIR/screen_$TIMESTAMP.png"

Passing Variables

You can make your scripts more flexible with variables:

#!/bin/bash

OUTPUT_DIR="$HOME/Screenshots"
DELAY=${1:-3}  # Default to 3 seconds if no argument provided
QUALITY=${2:-75}  # Default to quality 75 if not specified

mkdir -p "$OUTPUT_DIR"
echo "Taking screenshot in $DELAY seconds..."
scrot -d "$DELAY" -q "$QUALITY" "$OUTPUT_DIR/screen_%Y%m%d_%H%M%S.png"

Error Handling

Robust scripts should include error checking:

#!/bin/bash

OUTPUT_DIR="$HOME/Screenshots"
mkdir -p "$OUTPUT_DIR"

if ! command -v scrot &> /dev/null; then
    echo "Scrot is not installed. Please install it first."
    exit 1
fi

if scrot "$OUTPUT_DIR/screen_%Y%m%d_%H%M%S.png"; then
    echo "Screenshot saved successfully"
else
    echo "Error taking screenshot"
    exit 2
fi

Automated Documentation Script

This more advanced script creates documentation for an application by taking screenshots of each window:

#!/bin/bash

APP_NAME="$1"
DOC_DIR="$HOME/Documentation/$APP_NAME"
mkdir -p "$DOC_DIR"

echo "Launching $APP_NAME..."
$APP_NAME &
APP_PID=$!

sleep 3  # Wait for app to start

echo "Taking screenshots of each window..."
for WINDOW_ID in $(xdotool search --pid $APP_PID); do
    WINDOW_NAME=$(xdotool getwindowname $WINDOW_ID)
    echo "Capturing: $WINDOW_NAME"
    xdotool windowactivate $WINDOW_ID
    sleep 1
    scrot -u "$DOC_DIR/${WINDOW_NAME// /_}.png"
    sleep 1
done

echo "Documentation screenshots saved to $DOC_DIR"
kill $APP_PID

Practical Use Cases

Scrot’s versatility makes it suitable for a wide range of applications beyond simple screen captures.

Documentation Creation

Technical writers can use Scrot to capture application interfaces for manuals:

scrot -u -b -d 3 application_interface.png

Combined with scripting, this allows for systematic documentation of software features.

Technical Support and Bug Reporting

System administrators can quickly capture and share system states:

scrot -d 1 "error_$(date +%s).png" -e 'echo "See attached screenshot" | mail -a "$f" -s "System Error" support@example.com'

This captures the screen and automatically emails it with context.

System Monitoring and Logging

Create visual logs of system status at regular intervals:

# In crontab
*/15 * * * * DISPLAY=:0 scrot /var/log/visual/$(date +\%Y\%m\%d)/$(date +\%H\%M).png

This provides visual context to system logs, helpful for troubleshooting intermittent issues.

Educational Tutorials

Educators can create step-by-step visual guides:

for i in {1..10}; do
  echo "Step $i: Perform action and press Enter"
  read
  scrot "tutorial_step$i.png"
done

This interactive approach ensures each step is captured at the right moment.

Security Monitoring

Set up motion-triggered screenshots for security purposes:

motion -c /etc/motion.conf -e "scrot /home/user/security/%Y-%m-%d_%H-%M-%S.jpg"

When combined with motion detection software, Scrot can document security events.

Tips and Tricks for Experts

After mastering the basics, these advanced techniques can help you get even more from Scrot.

Keyboard Shortcuts

Create global keyboard shortcuts for quick captures:

# Add to your window manager configuration (e.g., ~/.config/openbox/rc.xml for Openbox)
<keybind key="Print">
  <action name="Execute">
    <command>scrot 'screenshot_%Y%m%d_%H%M%S.png' -e 'mv $f ~/Screenshots'</command>
  </action>
</keybind>

Useful Aliases

Add these to your shell configuration file:

# Full screenshot
alias ss='scrot ~/Screenshots/%Y-%m-%d_%H-%M-%S.png'

# Window screenshot
alias ssw='scrot -u -b ~/Screenshots/%Y-%m-%d_%H-%M-%S.png'

# Selection screenshot
alias sss='scrot -s ~/Screenshots/%Y-%m-%d_%H-%M-%S.png'

Post-Processing Integration

Automatically optimize screenshots:

scrot -e 'pngquant $f --output "${f%.*}-optimized.png" && rm $f'

Or add watermarks:

scrot -e 'convert $f -gravity SouthEast -fill white -pointsize 20 -annotate +10+10 "© $(date +%Y)" $f'

Multi-Image Sequences

Capture a series of screenshots at regular intervals:

for i in {1..10}; do scrot "sequence_$i.png"; sleep 5; done

Remote System Monitoring

When combined with SSH, Scrot can capture remote displays:

ssh user@remote "DISPLAY=:0 scrot -" > remote_screenshot.png

Troubleshooting Common Issues

Even a simple tool like Scrot can sometimes encounter problems. Here are solutions to the most common issues.

Permission Problems

If you encounter “Can’t open X display” errors:

# Check that you have permission to access the X server
xhost +SI:localuser:$USER

# For cron jobs, try
XAUTHORITY=/home/username/.Xauthority DISPLAY=:0 scrot ...

Multi-Monitor Configurations

If screenshots only capture one monitor:

# Use the -m flag for multi-monitor setups
scrot -m multihead.png

For more control, you might need to specify coordinates with tools like ImageMagick after capture.

Display Server Compatibility

For Wayland sessions:

# Try using with XWayland
DISPLAY=:0 scrot ...

# Or consider alternatives like grim for native Wayland support

Image Quality Issues

If text appears blurry:

# For PNG, ensure you're not using compression that affects quality
scrot -z 0 high_quality.png

# For JPEG, use maximum quality
scrot -q 100 best_quality.jpg

Filename and Path Problems

If files aren’t saving where expected:

# Check for typos in paths
scrot "$HOME/Screenshots/test.png"

# Ensure directories exist
mkdir -p "$HOME/Screenshots" && scrot "$HOME/Screenshots/test.png"

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button