LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-04-2012, 08:11 AM   #1
dragonix
Member
 
Registered: Nov 2012
Location: Belgium
Distribution: Ubuntu 12.04
Posts: 69
Blog Entries: 6

Rep: Reputation: 1
Grep recursive usage


Hi all

The cause of my problem is most likely the amount of folders/files..

Anyway, so what I try to do is to search for a combination within a file (grep...)
But I have multiple folders (let's say almost 1000 ) and the way I use it, is as follows

Code:
grep -lr <what_to_look_for> ./
After entering, he gives me the first result almost instantly, but then nothing more (waiting couple of minutes now..)

Did I do something wrong?

Thanks!
 
Old 12-04-2012, 08:23 AM   #2
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
Depending on how many files, what kind of files and size of the files in your directories, this may indeed take some time to finish. Also, if you have any symlinks in your directories, it may cause problems.
 
Old 12-04-2012, 08:36 AM   #3
dragonix
Member
 
Registered: Nov 2012
Location: Belgium
Distribution: Ubuntu 12.04
Posts: 69

Original Poster
Blog Entries: 6

Rep: Reputation: 1
The files itself are not that large (couple of KB, smaller than 10-20KB)
But I do have a large amount of files that needed to be checked.
So I would think that he would show the ones he has checked, or is that only after the command has ran completely?
 
Old 12-04-2012, 08:57 AM   #4
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
grep reports only the files which contain the search pattern, but not the files that don't. So if there are no files with the pattern it will not report anything.
 
1 members found this post helpful.
Old 12-04-2012, 09:43 AM   #5
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Also, if grep encounters any FIFOs or sockets in the area being searched, it can sit forever waiting for input. You would need to use the "--devices=skip" option to prevent that.
 
1 members found this post helpful.
Old 12-04-2012, 05:59 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
grep shows matches as they are found, so you need to wait for the prompt to re-appear, unless it has the problems mentioned by rknichols.
You can avoid those by using 'find' and specifying '-type f', so it only checks regular files.
 
1 members found this post helpful.
Old 12-05-2012, 12:34 AM   #7
dragonix
Member
 
Registered: Nov 2012
Location: Belgium
Distribution: Ubuntu 12.04
Posts: 69

Original Poster
Blog Entries: 6

Rep: Reputation: 1
Quote:
Originally Posted by TobiSGD View Post
grep reports only the files which contain the search pattern, but not the files that don't. So if there are no files with the pattern it will not report anything.
Yes, I know but I am more than 100% sure that he HAS to find more results and trust me I know
But thanks for the pointer!

Quote:
Originally Posted by rknichols View Post
Also, if grep encounters any FIFOs or sockets in the area being searched, it can sit forever waiting for input. You would need to use the "--devices=skip" option to prevent that.
True, I haven't tried it yet but I think it is most unlikely that there are any devices in that folder.. But I will give it a shot!
Thanks!

Quote:
Originally Posted by chrism01 View Post
grep shows matches as they are found, so you need to wait for the prompt to re-appear, unless it has the problems mentioned by rknichols.
You can avoid those by using 'find' and specifying '-type f', so it only checks regular files.

I tried what rknichols suggested, but it has the same results..
Code:
find . -type f -exec grep -lr --device=skip <criteria> {} \;

Last edited by dragonix; 12-05-2012 at 12:42 AM.
 
Old 12-05-2012, 12:46 AM   #8
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,846

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
If you assumed grep failed to find some files try to execute it in a smaller directory (containing your suspects). Probably your regexp is not perfect.
 
Old 12-05-2012, 12:47 AM   #9
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
Quote:
Originally Posted by dragonix View Post
Yes, I know but I am more than 100% sure that he HAS to find more results and trust me I know
Show us the actual command you use, including the search pattern and an example file (or the relevant part of a file) that contains that pattern, but is not found by your command.
 
Old 12-05-2012, 01:04 AM   #10
dragonix
Member
 
Registered: Nov 2012
Location: Belgium
Distribution: Ubuntu 12.04
Posts: 69

Original Poster
Blog Entries: 6

Rep: Reputation: 1
Quote:
Originally Posted by TobiSGD View Post
Show us the actual command you use, including the search pattern and an example file (or the relevant part of a file) that contains that pattern, but is not found by your command.
The actual command
Code:
$ find . -type f -exec grep -lr --devices=skip "21200" {} \;
Small partion of a file
Code:
<App_Data App="MOD" Name="Type" Value="title"/>
<App_Data App="MOD" Name="Advisories" Value="AL"/>
<App_Data App="MOD" Name="Aspect_Ratio" Value="16:9"/>
<App_Data App="MOD" Name="Billing_ID" Value="21200"/>
So the last part is the thing I'm looking for.

The folder structure is as follows
Code:
/directory (here is where I do my find/grep)
/directory/directory1
/directory/directory1/file1
/directory/directory1/file2
/directory/directory1/file3
/directory/directory2
/directory/directory2/file1
/directory/directory2/file2
/directory/directory2/file3
...
 
Old 12-05-2012, 01:32 AM   #11
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,846

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
probably you can try grep -lrF 21200 to speed it up a bit
 
1 members found this post helpful.
Old 12-05-2012, 02:03 AM   #12
dragonix
Member
 
Registered: Nov 2012
Location: Belgium
Distribution: Ubuntu 12.04
Posts: 69

Original Poster
Blog Entries: 6

Rep: Reputation: 1
Seems to give me the same result...
And please, trust me when I see that he should be giving more solutions

But I will try it first in a smaller directory

EDIT
Tried it in a smaller folder-structure and there it seems to go fine..
So the problem is that the original folder-structure is too large... (did a count -> almost 2000 folders )

Last edited by dragonix; 12-05-2012 at 02:14 AM.
 
Old 12-05-2012, 02:56 AM   #13
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
Quote:
Originally Posted by dragonix View Post
Code:
$ find . -type f -exec grep -lr --devices=skip "21200" {} \;
Out of curiosity, why do you use both find and grep -r?
 
Old 12-05-2012, 03:02 AM   #14
dragonix
Member
 
Registered: Nov 2012
Location: Belgium
Distribution: Ubuntu 12.04
Posts: 69

Original Poster
Blog Entries: 6

Rep: Reputation: 1
Quote:
Originally Posted by millgates View Post
Out of curiosity, why do you use both find and grep -r?
Not sure how to look IN a file with the find-command and without grep.
But if you mean why I use the -r argument, tbh I thought, meh it doesn't hurt to use it again (while I know that the find commands looks in every directory beneath the one you specified, but correct me if I'm wrong )

Last edited by dragonix; 12-05-2012 at 03:05 AM.
 
Old 12-05-2012, 04:16 AM   #15
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
You don't need to use -r for grep; let find take care of recursion.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
recursive grep speed allasso Linux - General 10 06-09-2010 07:22 PM
how does recursive grep work? serutan Linux - Newbie 5 07-11-2008 01:00 PM
Sorting recursive 'ls' and 'grep' SirTristan Linux - Newbie 5 03-13-2008 02:39 PM
recursive grep xpucto Solaris / OpenSolaris 2 05-29-2007 09:57 AM
Recursive grep jimieee Linux - General 5 10-06-2003 10:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration