LinuxQuestions.org

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

stf92 04-25-2012 01: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 01:20 PM

No, you need to run
Code:

updatedb
You can use a cronjob if needed.

Kind regards

stf92 04-25-2012 01: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 01:39 PM

You are right, curious to know how this works.

Kind regards

astrogeek 04-25-2012 02: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 03: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 04: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 05:42 PM

It happens that I always run locate as root.

manu-tm 04-25-2012 07: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 08: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 09: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 09: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 11:44 AM

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 11:55 AM

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 06: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.

stf92 04-27-2012 08:28 AM

But is there not a way to exclude a certain path when running locate without having to update the database again? Of course there is always locate beethoven | grep -v /home/semoi/bee9

David the H. 04-27-2012 09:02 AM

Ah-ha. I just realized my mistake. I was talking about the locate from findutils, not slocate. :doh: Ignore my last post.

stf92 04-27-2012 12:46 PM

Thanks for your post anyways and regards.

chrisretusn 04-29-2012 03:23 AM

Quote:

Originally Posted by stf92 (Post 4664488)
But is there not a way to exclude a certain path when running locate without having to update the database again? Of course there is always locate beethoven | grep -v /home/semoi/bee9

Sadly these is not, your grep solution is a winner. I also sometimes just go with find. :)

stf92 06-28-2012 05:30 AM

Quote:

Originally Posted by chrisretusn (Post 4663107)
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.


Fine. Now watch this:
Code:

semoi@darkstar:/hdaal/sma_/info$ locate beethoven
/home/semoi/bee9/beethoven9.md5
semoi@darkstar:/hdaal/sma_/info$ rm /home/semoi/bee9/beethoven9.md5
semoi@darkstar:/hdaal/sma_/info$ locate beethoven
/home/semoi/bee9/beethoven9.md5
semoi@darkstar:/hdaal/sma_/info$

Are you not speaking about some slocate version > 3.1?


All times are GMT -5. The time now is 02:51 PM.