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> ./ Did I do something wrong? Thanks! |
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.
|
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? |
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.
|
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.
|
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. |
Quote:
But thanks for the pointer! Quote:
Thanks! Quote:
I tried what rknichols suggested, but it has the same results.. :( Code:
find . -type f -exec grep -lr --device=skip <criteria> {} \; |
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.
|
Quote:
|
Quote:
Code:
$ find . -type f -exec grep -lr --devices=skip "21200" {} \; Code:
<App_Data App="MOD" Name="Type" Value="title"/> The folder structure is as follows Code:
/directory (here is where I do my find/grep) |
probably you can try grep -lrF 21200 to speed it up a bit
|
Seems to give me the same result...
And please, trust me when I see that he should be giving more solutions :p 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 :D) |
Quote:
|
Quote:
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 ;)) |
You don't need to use -r for grep; let find take care of recursion.
|
All times are GMT -5. The time now is 08:17 PM. |