neil.k
June 9, 2011, 10:03am
1
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:
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.
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".
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.
click
June 9, 2011, 10:15am
2
neil.k:
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:
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.
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".
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.
Correct, you need to be root in order not to have "Permission denied" and search the hole system
Same as the first just replace the . with /
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
gary_w
June 9, 2011, 10:28am
3
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.