Getting error "xargs unterminated quote" when tried to print the number of lines in terminal

Viewed 37488

I want to get the number of lines in my application. I am using this code:

find . "(" -name "*.m" -or -name "*.h" ")" -print | xargs wc -l

It is working fine in other applications but for one of my applications it is giving the error "xargs unterminated quote".

5 Answers

The canonical way to solve quotes, spaces and special characters problems when using find is to use the -exec option instead of xargs.

For your case you can use:

find . "(" -name "*.m" -or -name "*.h" ")" -exec wc -l "{}" \;

After some tinkering, I found that this command worked for me (because I had spaces and unmatched quotations in my filenames):

find . -iname "*USA*" -exec cp "{}" /Directory/to/put/file/ \;

. refers to the location the search is being run

-iname followed by the expression refers to the match criteria

-exec cp "{}" /Directory/to/put/file/ \; tells the command to execute the copy command where each file found via -iname replaces "{}"

You need the \; to denote to the exec command that the cp statement is ending.

Solved by replacing from source " with \"

Related