Grep through all files in subdirectories




















You could do :. You don't even need the --include; "grep -r perl. If you had a directory strucure like this:. But if you are on some old Unix without recursive capabilities in its grep, it gets very hard.

The problem with all the reponses that invariably pop up for this type of question is that none of them are ever truly fast and most of them aren't truly robust.

Typically, the answer is to use find, xargs, and grep. That's horribly slow for a full filesystem search, and it's painfully difficult to properly construct a pipeline that will avoid searching binaries if you don't want to, won't get stuck on named pipes or blow up on funky filenames beginning with -, or sometimes spaces, punctuation etc.

There are ways around all these things, but they are all ugly. BTW, something that almost never gets mentioned but that I will frequently use under conditions where it is appropriate is a simple.

Not useful much beyond that, and may not even be good at that except for certain starting points, but it's faster than any find xargs pipeline can ever be if the set is small enough.

But it also has bugs if the filenames could have "-" at their beginning. Fixing that can be a little nasty. That's pretty awful, but it's what you have to get into if you have special cases.

Special cases are what makes this question more difficult. If you have a small number of files and subdirs to search, the simple approach may work fine for you. If not, you have to get more creative. November, Excuse the interuption, but there is something new to talk about and I didn't want you to have to go all the way to the comments to find it.

It's called "ack", it's written in Perl, and it addresses the things the things this page talks about. Glimpse indexes files by the words contained in the file. Then when you want to search all of the files, it only runs its equivalent of grep agrep on the files that contain the words you're looking for. You can search for partial words too, though it takes longer.

I have the man pages, include files, rfcs, source trees, my home directory, web pages, etc. See also: Find with -execdir and Grep in Depth. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

There is no reason anyone would want a computer in their home. Ken Olson, president, chairman and founder of DEC. How can I recursively grep through sub-directories? Unix Articles. Related Articles. Collectives on Stack Overflow. Learn more. Asked 9 years, 8 months ago. Active 8 years, 9 months ago.

Viewed 53k times. Thank you! Romonov Romonov 7, 10 10 gold badges 41 41 silver badges 54 54 bronze badges. Add a comment.

Active Oldest Votes. Great explanation of each argument! You can use the following command to answer at least the first part of your question. Hakan Serce Hakan Serce I works in my Ubuntu machine. Can you try using just find. Same message. My system is redhat.

Can you check by putting the name of the current folder explicitly in place of dot. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password.



0コメント

  • 1000 / 1000