xargs: unmatched single quote
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:
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:
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:
find . -type f -print0 | xargs -0 grep string
-M.
>







24th November 2007, 04:10
Hi Marius,
Thanks for the tip. Another tip to search a string inside the search results,
====
find . -type f -exec grep string {} \;
====
Thanks
Anil
24th November 2007, 18:18
recursive grep is nice too !
grep -R string .
10th January 2008, 06:50
find . -type f | xargs -d ‘\n’ grep string
26th December 2008, 21:24
been working on tar piping my whole music stash. accidentally created a bunch of ‘*.mp3.gz’ so, to undo that I ran your command
find . -name ‘*.gz’ -type f -printf ‘”%p”\n’ | xargs rm -f
It deleted all the .gz files no problem .. and it deleted my mp3s!!!!!!
I stopped it before it destroyed my entire stash (I was wondering why it took so long and cntrl-c)
Now I will have to try to get data from an alternative store