1827808 Members
2112 Online
109969 Solutions
New Discussion

find command

 
SOLVED
Go to solution
prasad_15
Advisor

find command

Hi,

Could anybody please tell me how do i get this.
I only need the directory which contains a.sql file . But it keeps showing me all the directory with this annoying
find: cannot open xxxx messages
when i do
find / -name a.sql -print

Thanks



4 REPLIES 4
Tim Adamson_1
Honored Contributor
Solution

Re: find command

Hi Prasad,

To get rid of the annoying messages, redirect std error:

find / -name a.sql -print 2>/dev/null


Cheers!
Yesterday is history, tomorrow is a mystery, today is a gift. That's why it's called the present.
Con O'Kelly
Honored Contributor

Re: find command

Hi

You get these messages if you are running the find command as a non root user. Its basically telling you that it cannot read directories as it doesn't have permission, therefore if your file resides in these directories, it won't find it.

To fix the "problem" run the command as root.

One bit of advice, running "find / ..." can have an impact on system performance. If you have some idea where the file is, narrow the search as in:
# find /oracle /application -name "a.sql" -print

For example this searches /oracle & /application directories & all sub directories for a.sql file.

Cheers
Con
Tim Adamson_1
Honored Contributor

Re: find command

Hi prasad,

Even better, if you want to return just the directory containing the file a.sql, try:

find / -name a.sql -exec dirname {} \; 2>/dev/null


Cheers!
Yesterday is history, tomorrow is a mystery, today is a gift. That's why it's called the present.
Eric Herberholz
Advisor

Re: find command

How about trying this:

find / -name a.sql -exec ls -ld {} \;

It works for me when I try to find master.d in /usr/conf with:

find /usr/conf -name master.d -exec ls -ld {} \;

Regards,
-erich (Eric Herberholz)