Automatically update locate DB in OS X

Pretty straightforward, simply add the following in your .bash_profile:

alias locate=’if [ $((`date +%s`-`eval $(stat -s /var/db/locate.database); echo $st_mtime`)) -gt 3600 ]; then echo “locate: db is too old!”>/dev/stderr; sudo /usr/libexec/locate.updatedb; fi; locate -i’

Note: Run source ~/.bash_profile to reload.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.