Hacker News new | ask | show | jobs
by babarock 5076 days ago
Continuing on this off-topic, this construct is not optimal and can possibly break if one of the filenames has some funky characters (spaces, line breaks, carriage returns, unprintable characters, ...). This happens (unfortunately) more often than you think, and it's a very good idea to learn how to used these commands defensively.

Basically you have two choices, depending on the Unix you're using:

- find ... -print0 | xargs -0 wc -l

- find ... -exec wc -l {} +

The second one is defined by POSIX and, as far as I know, works on every Unix except for OpenBSD (who only implemented this feature starting version 5.1 in 2012).

The first one is non-POSIX so several Unices do not implement -print0.

To the best of my knowledge, GNU find should work fine with both.

More info: http://unix.stackexchange.com/a/41745/4098