LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   searching directory and subdirectories to no avail (https://www.linuxquestions.org/questions/linux-newbie-8/searching-directory-and-subdirectories-to-no-avail-4175579804/)

babysteps123 05-14-2016 05:00 PM

searching directory and subdirectories to no avail
 
How do I identify a file in a directory called /sch which contains the line: security = user

I need to search in the subdirectories inside /sch as well

trying find /sch -name "security = user" literally did nothing and after I hit enter it just went to the next line.

astrogeek 05-14-2016 05:06 PM

Welcome to LQ.

Your find command does not find files which "contain" that string, it would potentially only find files with "name" of the same string, hence the "-name" option, and the failure.

Try man grep, look at the -l and -r options for starters.

babysteps123 05-14-2016 05:19 PM

Quote:

Originally Posted by astrogeek (Post 5545572)
Welcome to LQ.

Your find command does not find files which "contain" that string, it would potentially only find files with "name" of the same string, hence the "-name" option, and the failure.

Try man grep, look at the -l and -r options for starters.

thank you for the welcome :) but both said no such file or directory. the options and patterns listed in man page is difficult for me to understand

astrogeek 05-14-2016 05:25 PM

What is the actual path that you want to search?

Please paste the exact command that you used and the error message it returned, so we can see better what is going on.

babysteps123 05-14-2016 05:30 PM

Quote:

Originally Posted by astrogeek (Post 5545580)
What is the actual path that you want to search?

Please paste the exact command that you used and the error message it returned, so we can see better what is going on.

grep -r /sch "security = user"
grep -l /sch"security = user"
All of them stated no such file or directory

grep -l -r "security = user"
This one didn't say anything under the line after I hit enter

babysteps123 05-14-2016 05:38 PM

Quote:

Originally Posted by astrogeek (Post 5545572)
Welcome to LQ.

Your find command does not find files which "contain" that string, it would potentially only find files with "name" of the same string, hence the "-name" option, and the failure.

Try man grep, look at the -l and -r options for starters.

I also just tried grep -R 'security = user" /sch
which gave weird results

astrogeek 05-14-2016 05:40 PM

Quote:

Originally Posted by babysteps123 (Post 5545582)
grep -r /sch "security = user"
grep -l /sch"security = user"
All of them stated no such file or directory

grep -l -r "security = user"
This one didn't say anything under the line after I hit enter

Ok thanks.

None of those are valid grep statements.

From man grep:

Code:

SYNOPSIS
      grep [OPTIONS] PATTERN [FILE...]
      ...

Your first two variations put the FILE, or path part (/sch) before the PATTERN part, "security = user". So it is trying to match the string '/sch' inside a file named "security = user". The third had no file name so it was waiting for you to type the input to search.

Try the first one the other way around and see what it does (try with -r and -l together).

astrogeek 05-14-2016 05:44 PM

Quote:

Originally Posted by babysteps123 (Post 5545585)
I also just tried grep -R 'security = user" /sch
which gave weird results

You will have to explain what weird results means as I am not familiar with the technical meaning of "weird"*... paste an example? ;)

*(Actually I am, but that is another context and would require a different thread!)

babysteps123 05-14-2016 06:36 PM

Quote:

Originally Posted by astrogeek (Post 5545590)
You will have to explain what weird results means as I am not familiar with the technical meaning of "weird"*... paste an example? ;)

*(Actually I am, but that is another context and would require a different thread!)

:) lol...Weird as in it gave me a few long files that had the folder name but not the "security = user" part in it...but I'm about to test out your explanation in your previous message to see if I get it now (I tried to copy & paste it but it wouldnt let me...also weird)

babysteps123 05-14-2016 06:45 PM

Quote:

Originally Posted by astrogeek (Post 5545586)
Ok thanks.

None of those are valid grep statements.

From man grep:

Code:

SYNOPSIS
      grep [OPTIONS] PATTERN [FILE...]
      ...

Your first two variations put the FILE, or path part (/sch) before the PATTERN part, "security = user". So it is trying to match the string '/sch' inside a file named "security = user". The third had no file name so it was waiting for you to type the input to search.

Try the first one the other way around and see what it does (try with -r and -l together).

so I think my :idea: might be flickering trying to turn all the way on...

after reading your explanation I tried this: grep -R "security = user" /sch & it gave me a few folders...2 were really long & they said no such file or directory (which made me wonder why did it even bother listing it if its not there).............................BUT then there are 2 files that say security = user at the end of them

astrogeek 05-14-2016 06:51 PM

Great!

Not sure what the other messages were without seeing them, but if it included the ones you were after then you are on the right track!

Thanks for following the path to enlightenment, I was not trying to be obtuse, but to get you to see how the man page relates to the syntax, and how the options and order are important!

If you can figure out the "extra" messages, post an example here and I am sure I or someone else will know what it means!

Also, here is an excellent overview of Linux and the various common commands that you should bookmark and follow: LINUX:
Rute User's Tutorial and Exposition


And again, welcoem to Linux and LQ!

Good luck!

babysteps123 05-14-2016 06:56 PM

Quote:

Originally Posted by astrogeek (Post 5545607)
Great!

Not sure what the other messages were without seeing them, but if it included the ones you were after then you are on the right track!

Thanks for following the path to enlightenment, I was not trying to be obtuse, but to get you to see how the man page relates to the syntax, and how the options and order are important!

If you can figure out the "extra" messages, post an example here and I am sure I or someone else will know what it means!

Also, here is an excellent overview of Linux and the various common commands that you should bookmark and follow: LINUX:
Rute User's Tutorial and Exposition


And again, welcoem to Linux and LQ!


Good luck!

Thank you for being so nice and helpful. I greatly appreciate it

astrogeek 05-14-2016 07:56 PM

You are welcome!


All times are GMT -5. The time now is 07:28 PM.