Click to See Complete Forum and Search --> : Find a file and search for a string within that file.
stumbles
09-15-2004, 09:43 PM
I'm not very good with the command line when it comes to all the different syntax that can be used with many of the commands.
Basically here is what I want to do. Search particular directory, in this example /var for a specific file named "BUILD". I then want to search within that file for a particular string, in this case "/usr/usr/share".
The reason is I've got a number of BUILD scripts and I suspect one of them is creating the above bogus directory. I don't want to manually look at about a hundred of those to find it.
AdamZ
09-15-2004, 10:06 PM
try this:
grep -H /usr/usr/whatever *BUILD*
That should search every file in the current directory with the name BUILD in it. The -H shows the filename that the match was found in.
stumbles
09-15-2004, 10:26 PM
Originally posted by blargety
try this:
grep -H /usr/usr/whatever *BUILD*
That should search every file in the current directory with the name BUILD in it. The -H shows the filename that the match was found in.
Says "no such file or directory".
My appologies, I should have more throughly read my post.
What I should have said; I want to search /var and all it's sub-directories for a specific file called "BUILD". I then want to search within that file for a particular string, in this case "/usr/usr/share".
teeitup
09-16-2004, 12:05 AM
Something like this maybe...
find . -type f -name 'BUILD' -exec grep -H '\/usr\/usr\/share' {} \;
I'm not positive about the pattern(/usr/usr/share). right slashes need to handled with care for proper results.
someone may correct my "pattern"
The output should give you file names reletive to where the command was issued. In your example you would execute the command from /var.
The line in the file with the pattern will be outputted also.
Good Luck,
tecknophreak
09-16-2004, 12:38 AM
Originally posted by stumbles
Says "no such file or directory".
My appologies, I should have more throughly read my post.
What I should have said; I want to search /var and all it's sub-directories for a specific file called "BUILD". I then want to search within that file for a particular string, in this case "/usr/usr/share".
Well, for the grep, first do the options, then what you are searching for, then the file/folder, i.e.
grep -HR /var BUILD
The R is for recursive.
stumbles
09-16-2004, 07:30 AM
Originally posted by tecknophreak
Well, for the grep, first do the options, then what you are searching for, then the file/folder, i.e.
grep -HR /var BUILD
The R is for recursive.
Ah ha.
This line worked for me;
grep /usr/usr/share -HR /var BUILD
It is the elfutils that created "/usr/usr/share".
My build script seems to have the prefix wrong.
Thanks for the help guys. I really need to hone up on command like stuff.