LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   locate command: on what basis, newly added files/folder will add to mlocate (https://www.linuxquestions.org/questions/programming-9/locate-command-on-what-basis-newly-added-files-folder-will-add-to-mlocate-4175511232/)

ddc 07-16-2014 01:16 AM

locate command: on what basis, newly added files/folder will add to mlocate
 
Hi,

What is the time interval to update newly added files/folders to mlocate.db?

I cannot execute "sudo udpatedb". why because, it needs authentication for current user.

I have added folder on ubuntu desktop. I waited for 30+ mins. Still, locate didn't list newly added folder. what is the secret behind this?

Thanks.

syg00 07-16-2014 01:30 AM

If it's your machine, enter your password. Else you'll have to wait until (probably) cron runs updatedb.

ddc 07-16-2014 01:40 AM

I am running this command through programmatically. I am using locate command to search for folder on user machine. While testing, added folder on desktop, but not listed same folder when I search through locate command. So, my question is, on what basis, mlocate.db gets updated? Any time interval (like for every x mins), for every login, or for every restart? what is the logic behind mlocate database update?

syg00 07-16-2014 02:04 AM

What part of the following was unclear ?.
Quote:

Originally Posted by me (Post 5204563)
Else you'll have to wait until (probably) cron runs updatedb.


ddc 07-16-2014 03:13 AM

You are correct. mlocate scheduled for every 6 hours, I checked with script which is available on stackoverflow. Do you have any idea how to change schedule?

I logged in as root, cd /etc and then executed crontab -l command. I am missing something so it's not listing cron jobs.

gnashley 07-16-2014 01:38 PM

changing config for cron needs root also. You seem to have several treads trying to solve the same problem. I think you really are stuck using find to find the files you want, when you want them.

ddc 07-17-2014 02:00 AM

@gnashley, I want to find folder in home directory without iterating file system. So, I chosen "locate" which is very fast and relies on mlocate database. But, as per my understandings, mlocate updates for every 6 hours. Now, I want to change the cron job scheduler to 2 mins. I want to edit mlocate cron. How to list the crons & edit them?

NevemTeve 07-17-2014 03:29 AM

Try these commands:
man 1 crontab
man 5 crontab

rknichols 07-17-2014 08:01 AM

Quote:

Originally Posted by ddc (Post 5205170)
@gnashley, I want to find folder in home directory without iterating file system. So, I chosen "locate" which is very fast and relies on mlocate database. But, as per my understandings, mlocate updates for every 6 hours. Now, I want to change the cron job scheduler to 2 mins. I want to edit mlocate cron. How to list the crons & edit them?

The mlocate job scans the whole filesystem and is a very expensive operation that typically takes more than 2 minutes to complete. Running it that often will cripple your system.

ddc 07-17-2014 09:01 AM

Thank you rknichols.

gnashley 07-17-2014 09:26 AM

Unless you have root rights, you cannot change the frequency of database updates run by cron.

rknichols 07-17-2014 03:12 PM

If you are just concerned about your home directory, consider running updatedb with overriding "--prune*" options to restrict its scan and a "-o" (--output) option to create a custom database. That would run a lot faster than the overall mlocate job, but you would need to run locate with the "-d" (--database) option to use your database. You could even trigger that scan from a program using the inotify(7) package that monitors the directories of interest.

michaelk 07-17-2014 03:59 PM

Just for your information...

Typically updatedb runs once a day from /etc/cron.daily and you can find the start time by examining your /etc/crontab file.

ntubski 07-17-2014 04:26 PM

Quote:

Originally Posted by rknichols (Post 5205275)
The mlocate job scans the whole filesystem and is a very expensive operation

But wasn't mlocate supposed to avoid scanning the whole filesystem:

Quote:

https://fedorahosted.org/mlocate/

mlocate is a locate/updatedb implementation. The 'm' stands for "merging": updatedb reuses the existing database to avoid rereading most of the file system,
Maybe it's still too expensive for a 2 minute frequency though.

rknichols 07-17-2014 11:13 PM

Quote:

Originally Posted by ntubski (Post 5205530)
But wasn't mlocate supposed to avoid scanning the whole filesystem:

It doesn't need to read the content of directories where the timestamp in the directory inode indicates that nothing has changed, but it still needs to stat(2) the inode of every directory in the database. Depending on what is in the kernel's inode cache, that can still require a lot of disk accesses. OK, running it every 2 minutes would keep the inodes in the cache and make it pretty fast, but that's at the expense of the memory needed for the cache. I guess it might be worth trying it to see what effect it has on the system.


All times are GMT -5. The time now is 04:24 PM.