Take screenshot from command line on an X server

By xngo on February 26, 2019

import is part of ImageMagick package. Note: Import will not work in MS Windows.

#import the "root" window - that is, the entire screen.
magick import -window root filename.png
 
magick import -window root screenshot-$(date +%Y-%m-%d_%k.%M.%S).png
 
# Take screenshots of the entire screen forever.
#    Useful when you also need to click on UI.
while true; do
    sleep 1s
    magick import -window root screenshot-$(date +%Y-%m-%d_%k.%M.%S).png
done

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.