[TAG] [2 cents TIP] efficient use of "-exec" in find

Mulyadi Santosa mulyadi.santosa at gmail.com
Sun Jan 31 12:39:55 MSK 2010


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




More information about the TAG mailing list