LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   Does locate update its database each time I remove a file? (http://www.linuxquestions.org/questions/slackware-14/does-locate-update-its-database-each-time-i-remove-a-file-941706/)

stf92 04-25-2012 02:14 PM

Does locate update its database each time I remove a file?
 
Hi: What's asked.

Kernel 2.6.21.5, Slackware 12.0
slocate 3.1

repo 04-25-2012 02:20 PM

No, you need to run
Code:

updatedb
You can use a cronjob if needed.

Kind regards

stf92 04-25-2012 02:24 PM

However, I've just made a test, running locate and then removing (rm) one of the listed files, and locate did not listed. How can that be?

repo 04-25-2012 02:39 PM

You are right, curious to know how this works.

Kind regards

astrogeek 04-25-2012 03:36 PM

From the slocate manual:

Quote:

Secure Locate provides a secure way to index and quickly search for all files on your system regardless
of ownership. It uses incremental encoding just like GNU locate to compress its database to make search-
ing faster, but it will also check file permissions and ownership before displaying matched entries so
that users will not see files they do not have access to
Presumably that would imply that if the file no longer exists then the user would not have access to it and it would not be displayed.

stf92 04-25-2012 04:56 PM

I would swear that locate went on displaying erased files long time after they had been erased as long as I did not run updatedb! What is curious is that I have not changed my slackware version.

astrogeek 04-25-2012 05:05 PM

Just a guess: Perhaps if you use locate as root it determines that you have no access restrictions and bypasses the permission tests - and therefore the 'existance' test as well.

stf92 04-25-2012 06:42 PM

It happens that I always run locate as root.

manu-tm 04-25-2012 08:05 PM

I'm not on Slackware. On Ubuntu, I always run updatedb as root. After that locate always give correct results.

chrisretusn 04-25-2012 09:54 PM

Quote:

Originally Posted by stf92 (Post 4662906)
Hi: What's asked.

Kernel 2.6.21.5, Slackware 12.0
slocate 3.1

No If you delete a file, it remains in slocate.db until the next update. That said, if you subsequently searched for that deleted file, locate (slocate) checks for physical existence, because that file no longer exist, it's entry in slocate.db will be removed. In this case the database is updated.

FYI, with a default, normal install of Slackware, updatedb is run daily at 0440 via a cron script in /etc/cron.daily/

stf92 04-25-2012 10:28 PM

Thanks very much. As to cron.daily, I removed the entry because sometimes updatedb began to run while I was burning optical media.

chrisretusn 04-26-2012 10:33 AM

Burning disk at 4:40am? That's dedication.... ;)

That shouldn't effect burning media, especially since updatedb is started with:
Code:

ionice -c3 nice -n 19 /usr/bin/updatedb -c /etc/updatedb.conf

David the H. 04-26-2012 12:44 PM

Note also that locate has two options (-e/-E) that check whether each matching file actually exists at that time, before printing the results. See the man page.

stf92 04-26-2012 12:55 PM

Well, my version is 3.1, from 2006, and only has
-e <dir1, dir2, ...>
which excludes those directories from the locate database.

This -e option would be very handy for me if only I knew how to use it. What I see is that
Code:

semoi@darkstar:/hdaal/sma_/info$ locate  beethoven
/home/semoi/bee9/beethoven9.md5
/home/semoi/bee9/beethoven-9-04-concertgebouw-klemperer-1956-16048.flac
/home/semoi/bee9/beethoven-9-01-concertgebouw-klemperer-1956-16048.flac
/home/semoi/bee9/beethoven-9-02-concertgebouw-klemperer-1956-16048.flac
/home/semoi/bee9/beethoven-9-03-concertgebouw-klemperer-1956-16048.flac
/home/semoi/beethoven9_vbr.m3u
semoi@darkstar:/hdaal/sma_/info$ locate  -e /home/semoi/bee9 beethoven
/home/semoi/bee9/beethoven9.md5
/home/semoi/bee9/beethoven-9-04-concertgebouw-klemperer-1956-16048.flac
/home/semoi/bee9/beethoven-9-01-concertgebouw-klemperer-1956-16048.flac
/home/semoi/bee9/beethoven-9-02-concertgebouw-klemperer-1956-16048.flac
/home/semoi/bee9/beethoven-9-03-concertgebouw-klemperer-1956-16048.flac
/home/semoi/beethoven9_vbr.m3u
semoi@darkstar:/hdaal/sma_/info$

That is, /home/semoi/bee9 was not excluded!

chrisretusn 04-27-2012 07:18 AM

The -e option is used in combination with the -u or-U options.

from locate, slocate, updatedb --help
Code:

  -e <dir1,dir2,...> - Exclude directories from the slocate database when
                        using the -u or -U options.

You best bet to exclude would be to add /home/semoi/bee9 to /etc/updatedb.conf

Code:

# /etc/updatedb.conf:  slocate configuration file

PRUNEFS="devpts NFS nfs afs proc smbfs autofs iso9660 udf tmpfs cifs"
PRUNEPATHS="/dev /proc /sys /tmp /usr/tmp /var/tmp /afs /net /media /mnt /home/semoi/bee9"
export PRUNEFS
export PRUNEPATHS

You will have to run updatedb again.


All times are GMT -5. The time now is 03:21 PM.