Tuesday, June 11, 2013

Re: [LINUX_Newbies] Re: Grep questions

 


Mi Jun 12 07:42:43 2013
Good morning
Thank You for help.

Hi Sophie,

> Good afternoon
> Do Jun 06 16:02:32 2013
> Thank You for help.
>
>
> | Can I search from every directory
> > | or should I always change to the root?
> >
> > You can search from anywhere. Just hand grep the pathname of where it
> > should look.
> *
> I want to search for files of the whole hd,
> so is it necessary to go to the root before I start grep?

If you use the 'find' command you do not have to change to the /directory.
So for example:
$ sudo find / -type f -name **** | grep ****
*
What do I want to do?
Most time I am searching old files
and I do not know the name of the file.
(When I know the name and directory then I do not search)
So
I look for tax mail and I know the
word
carinsurance
is in the file.

So is it better to search on the whole computer
by grep
like

or find?

grep -r "thisismyAIM" * > resu.txt

This will look for files in / and go recursively through all
subdirectories, regardless of the present directory you are in right now
(In case you are unsure, and the command prompt does not display the
location type 'pwd' to find out your present working directory). As
Trevor and Mani mentioned you need root permission to grep through files
in your / directory, therefor I included 'sudo' at the beginning.
*
Also do I need root permission for selfwritten txt Files?

Is this right:
Linux offers a lot of search commands.
So at the beginning I am using one easy command.
Later I am sure I will study all kind of search commands.
Thank You again for the URl
this was very helpful with nice examples.

To search in the current directory substitute . for /
*
OK

You can also specify directories to be searched for, then use '-type d'

The option '-name' searches for the exact name you provide, the option
'-iname' ignores lower and upper case and gives you all
files/directories with that name.

In case you want to leave out certain directories, /media or /run say,
use this

find / -type f -name **** \( ! -name /media\) -prune
*
Thank You
most times I am searching for old files
and I do not know the name
only a word out of the txt.

The backslashes are needed in order to escape the parentheses (). The
'-prune' option prevents find from ignoring the parent directory you
excluded, but still search through its subdirectories, for example
/media/USB
*
OK

I hope this helps,
*
Yes
Thank You.

Pascal

Regards
Sophie

__._,_.___
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (11)
Recent Activity:
To unsubscribe from this list, please email LINUX_Newbies-unsubscribe@yahoogroups.com & you will be removed.
.

__,_._,___

No comments:

Post a Comment