Ubuntu – xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option

xargs

I'd like to count all the ordinary file on home directory with commands:

$ find ~ -type f | xargs echo | wc -w
xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option

It prompts

xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option

What's the problem with usage?

Best Answer

It appears that some of your filenames have apostrophes (single quote) in their names.

Luckily, find and xargs have ways around this. find's -print0 option along with xargs's -0 option produce and consume a list of filenames separated by the NUL (\000) character. Filenames in Linux may contain ANY character, EXCEPT NUL and /.

So, what you really want is:

 find ~ -type f -print0 | xargs -0 --no-run-if-empty wc -w

Read man find;man xargs.

Related Question