Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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..)
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.
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
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
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..
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.
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.
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.
/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
...
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 )
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 )
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.