Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File search

Status
Not open for further replies.

pho01

Programmer
Mar 17, 2003
218
US
I know that a specific file is present on a unix system. How do I do a 'find' so I can find the path to that file location?

thanks
 
find / -type f -name myFileNameHere

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Mr Vlad is correct, however in some older versions
of 'find' you also need to add the -print option
or you won't get any output. Nowadays it's the
default so you don't need to add it. Also, you
may not want to start in the root directory (/)
as the search will cover all reachable subdirectories
generating lots of error messages where you don't
have execute permission. A typical solution for
this problem is to redirect all the error messages
to /dev/null (the rathole) like this:

find / -name filename -print 2>/dev/null

Remember, that first slash / is the root directory.
Provide a starting place farther down the hierarchy
if you want the search to run faster. The 'find'
command recurses through all lower subdirectories
from the point where you start it.
Dick S.
 
Thanks all,

If I did it from root (/), i gets bunch of denied permission error, such as:
find: can't read /dir/lost+found: Permission denied

how do I turn it off? which I meant that it will search the file at the location where it has read permission silently?
 
You avoid the error messages by redirecting
them to /dev/null as I mentioned in my
previous post. Try this:
find / -name filename -print 2>/dev/null
Dick S.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top