[K12OSN] OT: bash scripting - check for permissions, check for existence of file in directory tree

David Hopkins dahopkins429 at gmail.com
Thu Sep 25 17:19:08 UTC 2008

What about using the locate command (which is much faster) in a
script? And then testing if the command returned successfully, e.g.

locate somefile
if [ $? -eq 0 ] then
# successfully located somefile
# operate on the file (or check that it is part of the correct
directory structure?)

$? returns the success/failure of the immediately preceding command.
and if run updatedb each night, locate will work for any but the most
recent files?

Dave Hopkins

On Wed, Sep 24, 2008 at 7:49 AM, Rob Owens
<rob.owens at biochemfluidics.com> wrote:
> Nils Breunese wrote:
>> Rob Owens wrote:
>>> Nils Breunese wrote:
>>>> Rob Owens wrote:
>>>>> 2) I need to check for the existence of a file somewhere in a directory
>>>>> tree (with lots of subdirectories).
>>>> ----
>>>> find <directory> -name <filename>
>>>> ----
>>> I thought of that, but suspected there might be a better way.  Guess I
>>> was wrong.
>> Better in what way?
> I'm not actually looking to find a file and output it, I need to perform
> some action if a file exists.  Since I don't know where the file is, I
> guess I've got to find it first...
> I was hoping there would be a recursive way of doing:  if [ -f $FILE ];
> then  (or some other one-liner).
> -Rob
> ********************************************************
> The information transmitted is intended only for the person or entity to
> which it is addressed and may contain confidential and/or privileged
> material. If you are not the addressee, any disclosure, reproduction,
> copying, distribution, or other dissemination or use of this transmission in
> error please notify the sender immediately and then delete this e-mail.
> E-mail transmission cannot be guaranteed to be secure or error free as
> information could be intercepted, corrupted lost, destroyed, arrive late or
> incomplete, or contain viruses.
> The sender therefore does not accept liability for any errors or omissions
> in the contents of this message which arise as a result of e-mail
> transmission. If verification is required please request a hard copy
> version.
> ********************************************************
> _______________________________________________
> K12OSN mailing list
> K12OSN at redhat.com
> https://www.redhat.com/mailman/listinfo/k12osn
> For more info see <http://www.k12os.org>

More information about the K12OSN mailing list