What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Universal configuration monitoring and system of record for IT.

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags





Commands tagged ImageMagick from sorted by
Terminal - Commands tagged ImageMagick - 65 results
sudo apt-get install ufraw
2015-08-20 20:37:00
User: dnlcorrea
Functions: install sudo

Convert RAW files (eg. .CR2) to JPEGs, PNGs and whatnot.

convert input.png -alpha set -channel A -fx 0.5 output.png
for i in {1..100}; do convert -background lightblue -fill blue -size 100x100 -pointsize 24 -gravity center label:$i $i.jpg; done
mogrify -resize 852x480 ./*.png
2013-12-24 12:42:06
User: evilsoup
Tags: ImageMagick

Requires ImageMagick to be installed; mogrify is the lesser-known sibling to convert -- it overwrites your original images, but allows you to work on batches of files without resorting to a loop.

convert image.jpg -resize 1x1 txt: | tail -1 | awk '{gsub(/[,\)]/," "); print $3+$4+$5}'
2013-12-11 09:13:00
User: sucotronic
Functions: awk tail

You can get the mean value for the colours in an image. Then you can determine, in general, how dark or bright is the image and run some other actions based on that. I'll recommend to readjust the brightness of the images using +sigmoidal-contrast option of imagemagick convert command.

for fil in *.JPG; do datepath="$(identify -verbose $fil | grep DateTimeOri | awk '{print $2"_"$3 }' | sed s%:%_%g)"; mv -v $fil $datepath.jpg; done
2013-08-02 01:42:04
Functions: mv

Requires ImageMagick.

Extracts date taken from image and renames it properly.

Based on StackOverflow answer.

mogrify -resize SIZE_IN_PIXELS *.jpg
2013-07-05 14:14:04
User: o0110o

Batch resize all images to a width of 'X' pixels while maintaing the aspect ratio.

This makes uses of ImageMagick to make life easier.

convert infile.png \( +clone -channel GB -evaluate set 0 +channel \) +append -region 50%x100% -channel R -evaluate set 0 +channel outfile.png
2013-04-30 20:46:02
User: bugmenot
Functions: set

Converts red-cyan 3D anaglyphs to side-by-side format viewable by crossing your eyes. Useful for people who don't have 3D glasses or prefer not to use one.

convert {1..12}.png MyMultiPageFile.pdf
2013-03-26 01:30:38
User: lpanebr

Creates a PDF from multiple images. One page per image.

If you want a specific arbitrary order you can use {1,3,5,10,12}

* you may use jpg, tif etc

** if you do use jpg images you might want to add "-compress Zip" as suggested below to prevent from having the images from being re-compressed.

for file in `ls *.png`;do convert $file -resize 65% new_$file; done
import -quality 90 screenshot.png
2013-02-07 01:38:59
User: TuxLyn

Now try this. Ones you see small cross arrow, double click on any window you like to make a screenshot "selectively".

import -window root -quality 98 screenshot.png
mogrify -crop <width>x<height>+<X-offset>+<Y-offset> *.png
mogrify -transparent white image*.png
2013-01-23 16:58:24
User: michelsberg

mogrify can be used like convert. The difference is that mogrify overwrites files:


Of course, other source colors can be used as well.

for file in *.jpg; do identify -format '%f %b %Q %w %h' $file; done
2012-11-16 10:06:35
User: phattmatt
Functions: file

Runs the identify command (from ImageMagick) on each jpg file in the current directory and returns image details according to the format parameter. The example here returns:

Filename FileSize Compression Width Height

More information about the available format options can be found here: http://www.imagemagick.org/script/escape.php

I usually redirect the output to a text file using "> listofdetails.txt" at the end. Spreadsheet magic can then be applied.

convert -size 100x100 xc:grey nopic100_100.jpg
2012-06-15 11:23:02
User: theduke

Quickly create a new image with a certain size and background color.

convert image1 image2 -resize '400x300!' MIFF:- | compare -metric AE -fuzz '10%' - null:
2012-04-17 11:25:34
User: dooblem

Outputs the number of different pixels.

2 params to increase tolerance:

* thumbnails size

* fuzz, the color distance tolerance

See http://en.positon.org/post/Compare-/-diff-between-two-images for more details.

identify -format "%[fx:w]x%[fx:h]" logo:
2012-02-19 08:29:56
User: dratini0

You can use the -format switch to get the size of the image. Replace "logo:" with your image.

identify image.jpg |grep -o "[[:digit:]]*x[[:digit:]]*" |tail -1
mogrify -colorspace Gray -rotate '-90>' -resize 600x800 -dither FloydSteinberg -colors 16 -format png *
2012-02-01 17:16:52
User: yoyoyojomo
optipng *.png


-dither FloydSteinberg produces a more uniform dither than the default.

for fn in xkcd*.png xkcd*.jpg; do echo $fn; read xw xh <<<$(identify -format '%w %h' $fn); nn="$(echo $fn | sed 's/xkcd-\([^-]\+\)-.*/\1/')"; wget -q -O xkcd-${nn}.json http://xkcd.com/$nn/info.0.json; tt="$(sed 's/.*"title": "\([^"]\+\)",.*/\1/' ...
2012-01-06 20:26:11
User: fpunktk
Functions: echo read wget

full command:

for fn in xkcd*.png xkcd*.jpg; do; echo $fn; read xw xh <<<$(identify -format '%w %h' $fn); nn="$(echo $fn | sed 's/xkcd-\([0-9]\+\)-.*/\1/')"; wget -q -O xkcd-${nn}.json http://xkcd.com/$nn/info.0.json; tt="$(sed 's/.*"title": "\([^"]*\)", .*/\1/' xkcd-${nn}.json)"; at="$(sed 's/.*alt": "\(.*\)", .*/\1/' xkcd-${nn}.json)"; convert -background white -fill black -font /usr/share/fonts/truetype/freefont/FreeSansBold.ttf -pointsize 26 -size ${xw}x -gravity Center caption:"$tt" tt.png; convert -background '#FFF9BD' -border 1x1 -bordercolor black -fill black -font /usr/share/fonts/truetype/freefont/FreeSans.ttf -pointsize 16 -size $(($xw - 2))x -gravity Center caption:"$at" at.png; th=$(identify -format '%h' tt.png); ah=$(identify -format '%h' at.png); convert -size ${xw}x$(($xh+$th+$ah+5)) "xc:white" tt.png -geometry +0+0 -composite $fn -geometry +0+$th -composite at.png -geometry +0+$(($th+$xh+5)) -composite ${fn%\.*}_cmp.png; echo -e "$fn $nn $xw $xh $th $ah \n$tt \n$at\n"; done

this assumes that all comics are saved as xkcd-[number]-[title].{png|jpg}.

it will then download the title and alt-text, create pictures from them, and put everything together in a new png-file.

it's not perfect, but it worked for nearly all my comics.

it uses the xkcd-json-interface.

though it's poorly written, it doesn't completely break on http://xkcd.com/859/

awk 'BEGIN{FS=":"; print "digraph{"}{split($4, a, ","); for (i in a) printf "\"%s\" [shape=box]\n\"%s\" -> \"%s\"\n", $1, a[i], $1}END{print "}"}' /etc/group|display
2011-12-04 01:56:44
Functions: awk printf

Parses /etc/group to "dot" format and pases it to "display" (imagemagick) to show a usefull diagram of users and groups (don't show empty groups).

lsmod | awk 'BEGIN{print "digraph{"}{split($4, a, ","); for (i in a) print $1, "->", a[i]}END{print "}"}'|display
2011-12-04 01:41:23
Functions: awk lsmod

parse "lsmod" output to "dot" format and pass it to "display". Without perl!

read -s PASS; echo $PASS | convert sensitive.jpg -encipher - -depth 8 png24:hidden.png
2011-11-25 18:15:23
User: kev
Functions: echo read
Tags: ImageMagick

Do not use JPEG, GIF, or any other 'lossy' image encoding with Encryption