LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   'man grep' caused my head to hurt (https://www.linuxquestions.org/questions/slackware-14/man-grep-caused-my-head-to-hurt-315851/)

slackb0t 04-21-2005 07:07 PM

'man grep' caused my head to hurt
 
ok I just read the man pages for grep.. I am no further ahead than when I started.. could someone please explain in simple terms what it's use is and maybe a few examples of where you would use it... thanks in advance

ps I remember I copied a command from this form with grep in it to find files.. but I can't seem to locate it anymore.. like to search /etc for *.new files.. so I could update config files etc..

xgreen 04-21-2005 07:35 PM

you try this...
http://www.tldp.org/LDP/Bash-Beginne...ect_04_02.html

slackb0t 04-21-2005 09:53 PM

thanks... that guide helped but I still can't figure out how to find files.. from what I read grep only finds words or 'expressions' within a file.. I am thinking I need to look into the find command more..

but I bookmarked that site and learned a lot.. thank you again.. I am about to google to see if there is something similiar for the find command..

cavalier 04-21-2005 09:59 PM

Let me give you the single most useful structure for "find":
Code:

find / -name bash
This command says find, starting at the root directory, a file named bash. Try it. It should at least find /bin/bash

I use some variant on this all the time to find files that aren't on my path.

Another, similar command, that I truly adore is "which":
Code:

which bash
This'll do the same thing, but it'll only work on files that are in your path, so you can find executables that are on your path quickly.

xgreen 04-21-2005 10:06 PM

ok this is how i search files, for example mynotes.txt

code :

find / -name *notes*

find = find cmd
/ = start search from root. if you want to serch within your home dir then find /home/xxx/ -name *notes*
*notes* = search any file name contains "notes"


now for the grep things..for example in /etc you to list out lilo.conf
code :

ls -l /etc | grep lilo

ls- l = you know right
/etc = path
| = this is called pipe means the output of ls -l /etc/ is directed to grep
grep = filter out expression given (in this case is lilo) from ls -l /etc

slackb0t 04-21-2005 10:06 PM

Quote:

I use some variant on this all the time to find files that aren't on my path.

This'll do the same thing, but it'll only work on files that are in your path, so you can find executables that are on your path quickly.

Thank you.. I have tried your examples... but could you explain to me what you mean by "on my path" .. I have seen this expression used before but was unclear as to it's meaning..

edit:
I have been playing around with the examples you guys have given me.. I think I have it worked out.. just one to clarify something

ls -l /etc | grep lilo and find /etc -name '*lilo*' should give you the same results

or

ls -l /home/x/* | grep burning is the same as find /home/x/ -name '*burning*'

is there one that is more appropriate? I am thinking that using find is better when there are subdirectories and ls is good if you know the directory?

Tinkster 04-21-2005 10:23 PM

$PATH is an environment variable ... it contains a colon-
separated list of directories in which the shell will look
for executables. Some things may not be "in your path",
e.g. if you're logged in as a normal user you won't have
iptables in your path ...


Cheers,
Tink

mcd 04-22-2005 03:44 AM

you can add things to you path in the ~/.bashrc file, among other places

Genesee 04-22-2005 06:07 PM

when you're done with those, another command to check out is "locate"

:cool:


All times are GMT -5. The time now is 10:53 PM.