Hide

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.

Hide

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:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands matching mogrify from sorted by
Terminal - Commands matching mogrify - 9 results
i=0; f=$(find . -type f -iregex ".*jpg");c=$(echo $f|sed "s/ /\n/g"| wc -l);for x in $f;do i=$(($i + 1));echo "$x $i of $c"; mogrify -strip $x;done
mogrify -resize 800\> *
find . -name '*'.tiff -exec bash -c "mogrify -format jpg -quality 85 -resize 75% {} && rm {}" \;
2009-08-10 18:27:10
Functions: bash find
4

Simple command to convert a large number of images into jpeg-format. Will delete originals after conversion.

mogrify -format jpg -quality 80 -resize 800 *.jpg
2009-03-27 13:30:26
User: pronoiaque
3

To resize photos without changing exif datas, pretty cool for gps tagging.

(Require ImageMagick)

mogrify -geometry 800x600 *.jpg
2009-12-08 19:23:19
User: mariusz
2

-geometry (preserves values of height and width given, and aspect ratio).

WARNING: While 'resize' creates resized copies of original files, 'mogrify' works on the original files, replacing them. It will overwrite the source files, use with caution, and backup regularly.

mogrify -transparent white image*.png
2013-01-23 16:58:24
User: michelsberg
2

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

http://www.imagemagick.org/www/mogrify.html

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

mogrify -crop <width>x<height>+<X-offset>+<Y-offset> *.png
for File in *.jpg; do mogrify -resize 1024 -quality 96 $File; done
mogrify -resize 1024 *.jpg
2009-02-11 00:01:29
User: mitzip
1

This command requires the imagemagick libraries and will resize all files with the .jpg extension to a width of 1024 pixels and will keep the same proportions as the original image.

mogrify -trim *png
2010-10-21 15:09:33
User: houghi
Tags: convert png trim
1

That should be a short as it can get.

mogrify -format gif -auto-orient -thumbnail 250x90 '*.JPG'&&(echo "<ul>";for i in *.gif;do basename=$(echo $i|rev|cut -d. -f2-|rev);echo "<li style='display:inline-block'><a href='$basename.JPG'><img src='$basename.gif'></a>";done;echo "</ul>")>list.html
2013-08-25 20:45:49
User: ysangkok
Functions: cut echo
1

The input images are assume to have the "JPG" extension. Mogrify will overwrite any gif images with the same name! Will not work with names with spaces.

for a in `ls`; do echo $a && convert $a -resize <Width>x<Height> $a; done
2009-08-02 22:35:24
User: leavittx
Functions: echo
0

Resizes all images in the curent directory to x resolution.

It is better than `mogrify -resize *.jpg` because of independence from extension of image (e.g. .jpg and .JPG) (:

for file in *.png; do mogrify -trim "$file"; done
mogrify -resize 600x800! *.jpg
2011-09-09 18:19:59
User: totti
0

- Backup data before reszie as it over write original

-To preserve aspect ratio remove !

mogrify -colorspace Gray -rotate '-90>' -resize 600x800 -dither FloydSteinberg -colors 16 -format png *
2012-02-01 17:16:52
User: yoyoyojomo
0
optipng *.png

http://www.mobileread.com/forums/showpost.php?p=147076&postcount=7

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

find . -name '*.jpg' -o -name '*.JPG' -print0 | xargs -0 mogrify -resize 1024">" -quality 40
2013-06-20 16:09:41
User: minnmass
Functions: find xargs
0

The "find $stuff -print0 | xargs -0 $command" pattern causes both find and xargs to use null-delineated paths, greatly reducing the probability of either hiccuping on even the weirdest of file/path names.

It's also not strictly necessary to add the {} at the end of the xargs command line, as it'll put the files there automatically.

Mind, in most environments, you could use find's "-exec" option to bypass xargs entirely:

find . -name '*.jpg' -o -name '*.JPG' -exec mogrify -resize 1024">" -quality 40 {} +

will use xargs-like "make sure the command line isn't too long" logic to run the mogrify command as few times as necessary (to run once per file, use a ';' instead of a '+' - just be sure to escape it properly).

find . -name '*.[Jj][Pp][Gg]' -exec mogrify -resize 1024">" -quality 40 {} \;
2013-06-21 13:27:25
User: hugme
Functions: find
0

The find command can do this on it's own. This is a shorter faster version, it also includes more advanced regex (it will find .Jpg etc). Find doesn't need a pipe, you can run it directly from the command.

mogrify -resize 852x480 *.png
2013-12-22 15:27:29
User: Tenzer
0

The mogrify command is also part of the ImageMagick suite, and is made to make changes to files in place.

mogrify -resize 852x480 ./*.png
2013-12-24 12:42:06
User: evilsoup
Tags: ImageMagick
0

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.

( while read File; do mogrify -resize 1024 -quality 96 $File; done ) < filelist
2009-02-08 02:48:26
User: Corsair
Functions: read
-1

Imagemagick library is used. If image format is not JPEG, the "quality" option should not be issued.

mogrify -modulate 100,100,70 ../../icons/32x32/*.png
mogrify -resize SIZE_IN_PIXELS *.jpg
2013-07-05 14:14:04
User: o0110o
-1

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

This makes uses of ImageMagick to make life easier.

find . -name '*.jpg' -o -name '*.JPG' | xargs -I{} mogrify -resize 1024">" -quality 40 {}
2013-06-20 15:20:29
Functions: find xargs
-2

First use find to find all the images that end with jpg or JPG in the current dir and all its children.

Then pipe that to xargs. The -I{} makes it so spaces in filenames don't matter.

The 1024">" makes it so it takes any image greater in dimension than 1024 and resizes them to 1024 width, but keeping aspect ratio on height.

Then it sets the image quality to 40.

Piping it through xargs means you avoid the file count limit, and you could run this on your entire file system if you wanted.