LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 05-14-2016, 05:00 PM   #1
babysteps123
LQ Newbie
 
Registered: May 2016
Posts: 10

Rep: Reputation: Disabled
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.
 
Old 05-14-2016, 05:06 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,219
Blog Entries: 11

Rep: Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170
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.
 
1 members found this post helpful.
Old 05-14-2016, 05:19 PM   #3
babysteps123
LQ Newbie
 
Registered: May 2016
Posts: 10

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by astrogeek View Post
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
 
Old 05-14-2016, 05:25 PM   #4
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,219
Blog Entries: 11

Rep: Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170
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.
 
1 members found this post helpful.
Old 05-14-2016, 05:30 PM   #5
babysteps123
LQ Newbie
 
Registered: May 2016
Posts: 10

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by astrogeek View Post
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

Last edited by babysteps123; 05-14-2016 at 05:31 PM.
 
Old 05-14-2016, 05:38 PM   #6
babysteps123
LQ Newbie
 
Registered: May 2016
Posts: 10

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by astrogeek View Post
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
 
Old 05-14-2016, 05:40 PM   #7
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,219
Blog Entries: 11

Rep: Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170
Quote:
Originally Posted by babysteps123 View Post
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).
 
1 members found this post helpful.
Old 05-14-2016, 05:44 PM   #8
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,219
Blog Entries: 11

Rep: Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170
Quote:
Originally Posted by babysteps123 View Post
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!)

Last edited by astrogeek; 05-14-2016 at 05:49 PM.
 
1 members found this post helpful.
Old 05-14-2016, 06:36 PM   #9
babysteps123
LQ Newbie
 
Registered: May 2016
Posts: 10

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by astrogeek View Post
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)
 
Old 05-14-2016, 06:45 PM   #10
babysteps123
LQ Newbie
 
Registered: May 2016
Posts: 10

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by astrogeek View Post
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 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
 
Old 05-14-2016, 06:51 PM   #11
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,219
Blog Entries: 11

Rep: Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170
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!
 
1 members found this post helpful.
Old 05-14-2016, 06:56 PM   #12
babysteps123
LQ Newbie
 
Registered: May 2016
Posts: 10

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by astrogeek View Post
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
 
Old 05-14-2016, 07:56 PM   #13
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,219
Blog Entries: 11

Rep: Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170Reputation: 3170
You are welcome!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
searching for iframe tags in a directory and subdirectories mia_tech Linux - General 4 12-24-2013 09:22 AM
directory does not contain enough space to extract temp files even w/ 15gigs avail? phon_ca Red Hat 5 09-05-2012 01:38 PM
[SOLVED] Find not searching subdirectories JosephS Linux - Software 6 07-12-2010 10:16 PM
searching a file in subdirectories with ls visitnag Linux - Newbie 4 04-23-2009 11:45 AM
-clear-avail and --merge-avail meks-r Debian 0 04-28-2005 02:14 PM

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

All times are GMT -5. The time now is 11:38 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration