-   Linux - Newbie (
-   -   xargs: unmatched single quote (

akudewan 02-12-2005 05:13 AM

xargs: unmatched single quote
I was learning some shell commands in a little more detail when I came across this situation:

I made a file by the name of foo, by giving this command. (pwd is /home/akudewan/files/)


$cat > foo.txt
This is a TEXT file

Now, combining the "find" and "grep" command, I will search for the words "TEXT" in my ~/files directory.

So, I did:


$find /home/akudewan/files -type f | xargs grep TEXT
xargs: unmatched single quote

I got the above error, and I got confused.

I made a subdirectory and did a "cd" to ~/files/temp/. Then I copied foo.txt here and also made another file "file.txt" I changed the command to:


$find /home/akudewan/files/temp -type f | xargs grep TEXT

As you can see, it worked. I tried the command again in the parent directory, but got the same error. I checked the permissions, no problem with them. So why is this happening? And what does the error mean?

jonaskoelker 02-12-2005 07:18 AM


My best guess is that the output of find contains a single quote.
One remedy for this could be:
$ find -type f | grep -ve "'" | xargs ...

perhaps you could post the output of these commands:

$ find
$ find --version
$ grep --version
$ xargs --version

-- Jonas

PS. "pwd is /home/akudewan/files/" is _slightly_ incorret: pwd is an abbreviation for 'print [current] working directory', whereas cwd is 'current working directory' (or something to that effect). Thus, it would have been more correct to say "cwd is /home/akudewan/files". I hope you don't think of this as criticism, I'm just trying to enlighten you ;)

akudewan 02-13-2005 01:02 AM

Thanks jonaskoelker. There was a file that had a single quote (bruce lee's jeet kune do.pdf) ;)

I renamed that file and the command worked perfectly. But how do I go about it if there is a quote?


$ find --version
GNU find version 4.1.7
$ grep --version
grep (GNU grep) 2.5

Copyright 1988, 1992-1999, 2000, 2001 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO

$ xargs --version
GNU xargs version 4.1.7

PS: thanks for correnting me about the pwd thing. (I thought it was "Present" working directory)

jonaskoelker 02-13-2005 05:29 AM

fixing the quotes:

$ find -type f | sed -e "s/'/\\'/g" | xargs grep -e 'some regex...'

the sed call translates all "'" into "\'" (quote to backslash quote).
In case you have files containing other funny characters (# and " in particular), you may want to escape those as well.
have a look at either 'man sed' or 'info sed'.

Also, you might want to upgrade grep, find and xargs (I run 2.5.1 and 4.1.20 x 2, respectively).

hope this helps,

Jonas Kölker

akudewan 02-14-2005 05:48 AM

Thanks for all the help jonaskoelker. I'll look into this more on google and on the man pages. I've got the overall gist.

mltsy 07-28-2014 12:16 PM

null delimiter!
In case anybody else is still finding this thread when searching for the same issue (like me):

find also has a -print0 option that separates output arguments with the null character, and xargs has a -0 flag to interpred arguments as delimited by the null character, which then also avoids interpreting backslashes and quotes as special. So:

find -type f -print0 | xargs -0 grep -e 'some regex...'

All times are GMT -5. The time now is 02:36 PM.