Sunday, June 9, 2013

[LINUX_Newbies] Re: Grep questions

 



Hi Sophie,

--- In LINUX_Newbies@yahoogroups.com, "highskywhy@..." <highskywhy@...> wrote:
>
>
> 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 ****

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.

To search in the current directory substitute . for /

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

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

I hope this helps,

Pascal

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

__,_._,___

No comments:

Post a Comment