[K12OSN] OT: bash scripting - check for permissions, check for existence of file in directory tree
Nils Breunese
nils at breun.nl
Thu Sep 25 17:28:45 UTC 2008
David Hopkins wrote:
> 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?)
> fi
>
> $? 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?
That works if the frequency at which your locate database is updated
if good enough for your application. You could add an extra check to
see if the file really exists after locate says it exists. You'll
still miss files that were created after the last time your locate
database was updated. If you want to have the most recent info about
your filesystem you'll just have to stick with find.
I guess it also depends on whether the directory you're searching has
a lot of files. If it's not too big it's probably not worth it to use
locate and sacrifice precision.
Nils Breunese.
More information about the K12OSN
mailing list