MDLog:/sysadmin

The Journal Of A Linux Sysadmin

Xargs: Unmatched Single Quote

| Comments

OK… Here is a short tip that might help others in the same situation: here i was running a simple find/grep command that I have always used to search for files matching some string; this was something simple like:

1
find . -type f | xargs grep string

And bum… After a while the command failed with the error: “xargs: unmatched single quote”. This happened because one of the files returned by the find command had a quote character inside its file name. xargs was not able to distinguish between the quote part of the file name and the quote used to quote names.

If you encounter a similar problems the solutions is to add -printf ‘“%p”\n’ to the find command line that will enclose all file names into double quotes:

1
find . -type f -printf '"%p"\n' | xargs grep string

if your find command does not have the -printf operand, you can try to use the -print0 operand and the command will look like:

1
find . -type f -print0 | xargs -0 grep string

-M.

Comments