find . -name “*.*” | xargs grep "help"

Hi all,

I am a unix noob. Need some basic help. I have tried using google, but not able to figure this out.

Here are the scenarios:

  1. How do I find a directory with a particular name, say "Merlin" in the entire file system? I tried :
find / -type d -name "dir_name"

The problem is I'm getting thousands of lines, most of them with "blah blah blah...Permission denied".

How can I have only the relevant information, the directory that I am looking for with its path.

  1. How do I find a file with name "unicorn", where I do not know it's directory location?
find . -name "unicorn" -print

.

Same problem, lots of hits with "permission denied".

  1. How do I find a file, where I do not know it's location which has a particular pattern inside the file.

This was a bummer. Couldn't find anything. Please help.

  1. Correct, you need to be root in order not to have "Permission denied" and search the hole system

  2. Same as the first just replace the . with /

  3. Find cannot look trough the contents of a file, this can be done with various scripts for example:

find / -type f | xargs grep "John Smith ID"

This will probaly print thousands of lines if you are not very specific about what you`re searching for, also it will run slow since it have to read every file on your disk. Good advise is at least to remember the directory where the file is.

For more see

man find
man grep
man locate
man whereis
man which 

Filesystem Hierarchy Standard - Wikipedia, the free encyclopedia

To get rid of the permission errors with find, redirect its STDERR to /dev/null (the bit bucket when you don't care about the output).

find / -type d -name "dir_name" 2>/dev/null

Also, "*.*" is a DOS thing. If you want to match everything, don't give find any name or iname at all.