Getting locate to work on Solaris

If you have worked in a Linux environment you may be used to the locate command. It is very convenient to find files thay may be scattered around the hard drive. Solaris does not have this command by default but it is very easy to install.

I’m going to assume you have installed Blastwave. Blastwave is a collection of pre-compiled packages for Solaris. If you haven’t installed Blastwave, here are the installation instructions.

locate is part of the GNU findutils. Using Blastwave it is very simple to install

# /opt/csw/bin/pkg-get -i findutils

One thing to notice is that in Blastwave findutils are command are prefixed with a g so locate is called glocate and updatedb is called gupdatedb.

Once it is installed we need you need to populate the initial database. Run the following command as root


# /opt/csw/bin/gupdatedb --prunefs="ctfs devfs proc mntfs tmpfs objfs fd hsfs nfs"

This tells updatedb to index everything except for the file systems listed here. The one you may want to have indexed is nfs but not in my case. This commands takes a while to run depending on how many files you have. When the command prompt returns we are ready to query the database


# /opt/csw/bin/glocate filesync
/usr/bin/filesync
/usr/share/man/man1/filesync.1

Now there is only one step left. You most likely want this database updated on a regular basis, e.g every Monday morning. You need to add the following entry to roots crontab for that to happen (if you don’t know how to edit roots crontab have a look at the crontab(1) man page)


0 3 * * 1 /opt/csw/bin/gupdatedb --prunefs="ctfs devfs proc mntfs tmpfs objfs fd hsfs nfs dev lofs sharefs"

This line will run gupdatedb every Monday morning at 3am.

Updated 20th of June 2007: added dev lofs and sharefs and excluded filesystems based on a comment from James Carlson on the opensolaris-discuss mailinglist.

[?]
Do you need system administration assistance? If you like what you are reading please consider subscribing to the RSS feed. If you have feedback or if you find the article useful please leave a comment below.

2 Responses to “Getting locate to work on Solaris”

  1. Thanks, this was a lifesaver. I couldn’t find locate at all. You were generous enough to volunteer that the package had been renamed glocate.

  2. It’s not that the package had been renamed glocate. There is not locate package in Solaris. You have to install find tools.

    As for /opt/csw/bin/pkg-get, there is of course no /opt/csw directory in Solaris X.

    Other than that, a fine how-to !

Leave a Reply