To improve the huge speed impact on find you could simulate something like locate
alias locate="if [ ! -e /tmp/locate.db -a ! -e /tmp/locate.lockdb ]
then touch /tmp/locate.lockdb
trap \"rm /tmp/locate.lockdb; rm /tmp/locate.db; exit\" SIGHUP SIGINT SIGTERM
find /|tee /tmp/locate.db
chmod 666 /tmp/locate.db
rm /tmp/locate.lockdb
elif [ -e /tmp/locate.lockdb ]
then find /
else cat /tmp/locate.db
fi|grep "
Of course there is an issue with permissions! It would be better to write some setuid commands for tee
and cat
to write the database in super user mode and at a better location but /tmp
.
A cheap alternative on most single or few user systems would be to write a per-user locate.db
somewhere near $HOME
.
Another nice alias is able to update/find. Hmm finally I think this alias works better than the original locate ;)
alias relocate="if [ ! -e /tmp/locate.lockdb ]
then rm /tmp/locate.db
fi
locate "
Edit I actually though that relocate should just be used like the locate alias above. If you use the relocate without an argument you get an error. The idea is to use relocate "no file to search for"
if you don't want to search but just update the database.
Ok, the find must be setuid'ed too. But then you can throw away your locate package.
The grep
argument should be passed through sed
to quote the .
dots.
NOTE FOR THE NOOBS: When I'm talking about setuid here DON'T SET THE SETUID FLAG ON TOOLS LIKE tee
,cat
or find
. This would be a security breach of your system! What I mean is to write secure alternatives for these simple commands that work in setuid mode and that work in a restricted way, just for the purpose to provide fitted tools for this alias.
*filename*
by default , butfind / -name filename
will search for exact filename , so find will requirefind / -name *filename*
man bash
and search forALIASES
and/orFUNCTIONS
for further detailsgit://git.savannah.gnu.org/findutils.git