This page looks best with JavaScript enabled

findutils locate configured correctly

 ·  ☕ 2 min read  ·  🤖 SWU

/etc/updatedb is missing in the current findutils, what to do?

In previous Linuxes I had the mlocate package installed. If I remember correctly, you could set the /etc/updatedb.conf to specify which directories were to be skipped for cron and a manual call to “sudo updatedb”. And I wanted to do that on a new Linux with the findutils locate package.

How do you configure findutils locate and updatedb?

Well, as I discovered, you can configure updatedb for cron, probably because it doesn’t run interactively. If you ignore the /home/user/secret directory in the cron configuration file for locate (actually updatedeb), it works for the cron call to updatedb, but a manual call to “sudo updatedb” doesn’t take that into account. Even a manually created /etc/updatedb.conf file is ignored.

Is there anything you can do to create the desired situation?

You can set it up, of course. The updateb tool does not take a configuration file into account, but it does have options that are evaluated and you can specify options in advance using environment variables. Environment variables for users in Linux are specified using shell configuration files. My shell is Bash, so that applies to ~/.bashrc - here I can specify the environment variable PRUNEPATHS for updatedb. Yes, but my user environment is not available through sudo, is it? Yes, that’s true, but sudo has an option to take all or a list of user environment variables with it. So I create an alias for sudo so that my new environment variable is included. This also works for Linuxes that don’t have a root user!

What does this look like in detail?

1
2
3
# soure /etc/updatedb.conf and export it
. /etc/updatedb.conf
export PRUNEPATHS
1
alias sudo="sudo --preserve-env=PRUNEPATHS"

Content of /etc/updatedb.findutils.cron.local

PRUNEPATHS="/home/user/geheim"

And then we create a symbolic reference:

cd /etc
ln -s updatedb.findutils.cron.local updatedb.conf

Conclusion

In a new shell, the ~/.bashrc is evaluated and we get the environment variable PRUNEPATHS. Its content is determined by the file /etc/updatedb.findutils.cron.local, which /etc/updatedb.conf points to. And the file ~/.bash_aliases is evaluated, which means that the input of sudo is replaced by sudo –preserve-env=PRUNEPATHS - this makes the environment variable PRUNEPATHS available in the sudo environment and takes it into account.

Goal achieved!

How to check success

Compare alias sudo against sudo take from path.
sudo env | wc -l
\sudo env | wc -l


wüsti
WRITTEN BY
SWU
human