Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

need to search for something in entire content

I am trying:

find . | xargs grep word

I get error:

xargs: unterminated quote

How to achieve this?

share|improve this question
add comment

migrated from stackoverflow.com Sep 21 '11 at 10:18

This question came from our site for professional and enthusiast programmers.

6 Answers

up vote 6 down vote accepted

xargs expects input in a format that no other command produces, so it's hard to use effectively. What's going wrong here is that you have a file whose name must be quoted on input to xargs (probably containing a ').

If your grep supports the -r or -R option for recursive search, use it.

grep -r word .

Otherwise, use the -exec primary of find. This is the usual way of achieving the same effect as xargs, except without constraints on file names. Reasonably recent versions of find allow you to group several files in a single call to the auxiliary command. Passing /dev/null to grep ensures that it will show the file name in front of each match, even if it happens to be called on a single file.

find . -type f -exec grep word /dev/null {} +

Older versions of find (on older systems or OpenBSD, or reduced utilities such as BusyBox) can only call the auxiliary command on one file at a time.

find . -type f -exec grep word /dev/null {} \;

Some versions of find and xargs have extensions that let them communicate correctly, using null characters to separate file names so that no quoting is required. These days, only OpenBSD has this feature without having -exec … {} +.

find . -type f -print0 | xargs -0 grep word /dev/null
share|improve this answer
    
+1 especially for /dev/null. It is a nuisance when the output format can vary, depending on how many files are matched... thanks. –  Peter.O Sep 22 '11 at 3:00
add comment

In the current directory you can use grep:

 grep -irl root .
share|improve this answer
add comment

There also ack, it's designed to skip special directories like .svn, .git and such. It's a daily tool for developers.

It's pretty close to for the common switches.

Ex. :

ack -r string .

Package ack-grep on debian & debian likes.

share|improve this answer
add comment

I think you want to find a string in files

Try find . -name "*" | xargs grep -l "string"

share|improve this answer
    
The error message from xargs ("Unterminated quote") means the OP has a file in . which has a quote in its name. Your line will croak on that as well. Like mu noted, you need a different termination. –  thiton Sep 21 '11 at 9:58
add comment

If you have the GNU tools (which you do if the Linux tag is accurate) then you can use -print0 and -0 to get around the usual quoting problems:

find . -type f -print0 | xargs -0 grep word
share|improve this answer
add comment

I guess you mean the first option

grep recursive, for searching content inside files

grep -R "content_to_search" /path/to/directory

ls recursive, for searching files that match

ls -lR | grep "your_search"
share|improve this answer
    
grep -rin for recursive-case_insensitive-show_line_number –  Feida Kila Sep 21 '11 at 9:31
    
I want to be able to search in content of each file. –  p2pnode Sep 21 '11 at 9:34
    
the first one returns any ocurrence in any file, specifying the file where the ocurrence was found –  Feida Kila Sep 21 '11 at 9:35
    
if solved mark the solution, thanks :) –  Feida Kila Sep 21 '11 at 9:40
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.