...making Linux just a little more fun!

2-Cent Tips

Two-cent Tip: efficient use of "-exec" in find

Mulyadi Santosa [mulyadi.santosa at gmail.com]


Sun, 31 Jan 2010 16:39:55 +0700

Most CLI aficionados use this kind of construct when executing a command over "find" results:

$ find ~ -type f -exec du -k {} \;

Nothing is wrong with that, except that "du" is repeatedly called with single argument (that is the absolute path and the file name itself). Fortunately, there is a way to cut down the number of execution:

$ find ~ -type f -exec du -k {} +

Replacing ";" with "+" would make "find" to work like xargs does. Thus du -k will be examining the size of several files at once per iteration.

PS: Thanks to tuxradar.com for the knowledge!

-- 
regards,
 
Mulyadi Santosa
Freelance Linux trainer and consultant
 
blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com

[ Thread continues here (2 messages/1.80kB) ]


Two-cent Tip: creating scaled up/down image with ImageMagick

Mulyadi Santosa [mulyadi.santosa at gmail.com]


Wed, 30 Dec 2009 11:42:36 +0700

Wants a quick way to scale up/down your image file? Suppose you want to create proportionally scaled down version of abc.png with width 50 pixel. Execute:

$ convert -resize 50x abc.png abc-scaled.png
-- 
regards,
 
Mulyadi Santosa
Freelance Linux trainer and consultant
 
blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com



Talkback: Discuss this article with The Answer Gang

Copyright © 2010, . Released under the Open Publication License unless otherwise noted in the body of the article. Linux Gazette is not produced, sponsored, or endorsed by its prior host, SSC, Inc.

Published in Issue 171 of Linux Gazette, February 2010

Tux