LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-16-2014, 01:16 AM   #1
ddc
LQ Newbie
 
Registered: Jul 2014
Posts: 13

Rep: Reputation: Disabled
Exclamation 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.
 
Old 07-16-2014, 01:30 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 16,752

Rep: Reputation: 2476Reputation: 2476Reputation: 2476Reputation: 2476Reputation: 2476Reputation: 2476Reputation: 2476Reputation: 2476Reputation: 2476Reputation: 2476Reputation: 2476
If it's your machine, enter your password. Else you'll have to wait until (probably) cron runs updatedb.
 
Old 07-16-2014, 01:40 AM   #3
ddc
LQ Newbie
 
Registered: Jul 2014
Posts: 13

Original Poster
Rep: Reputation: Disabled
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?

Last edited by ddc; 07-16-2014 at 01:41 AM.
 
Old 07-16-2014, 02:04 AM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 16,752

Rep: Reputation: 2476Reputation: 2476Reputation: 2476Reputation: 2476Reputation: 2476Reputation: 2476Reputation: 2476Reputation: 2476Reputation: 2476Reputation: 2476Reputation: 2476
What part of the following was unclear ?.
Quote:
Originally Posted by me View Post
Else you'll have to wait until (probably) cron runs updatedb.
 
1 members found this post helpful.
Old 07-16-2014, 03:13 AM   #5
ddc
LQ Newbie
 
Registered: Jul 2014
Posts: 13

Original Poster
Rep: Reputation: Disabled
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.
 
Old 07-16-2014, 01:38 PM   #6
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,890

Rep: Reputation: 569Reputation: 569Reputation: 569Reputation: 569Reputation: 569Reputation: 569
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.
 
2 members found this post helpful.
Old 07-17-2014, 02:00 AM   #7
ddc
LQ Newbie
 
Registered: Jul 2014
Posts: 13

Original Poster
Rep: Reputation: Disabled
@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?
 
Old 07-17-2014, 03:29 AM   #8
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,505

Rep: Reputation: 1080Reputation: 1080Reputation: 1080Reputation: 1080Reputation: 1080Reputation: 1080Reputation: 1080Reputation: 1080
Try these commands:
man 1 crontab
man 5 crontab
 
1 members found this post helpful.
Old 07-17-2014, 08:01 AM   #9
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 3,943

Rep: Reputation: 1719Reputation: 1719Reputation: 1719Reputation: 1719Reputation: 1719Reputation: 1719Reputation: 1719Reputation: 1719Reputation: 1719Reputation: 1719Reputation: 1719
Quote:
Originally Posted by ddc View Post
@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.
 
1 members found this post helpful.
Old 07-17-2014, 09:01 AM   #10
ddc
LQ Newbie
 
Registered: Jul 2014
Posts: 13

Original Poster
Rep: Reputation: Disabled
Thank you rknichols.
 
Old 07-17-2014, 09:26 AM   #11
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,890

Rep: Reputation: 569Reputation: 569Reputation: 569Reputation: 569Reputation: 569Reputation: 569
Unless you have root rights, you cannot change the frequency of database updates run by cron.
 
Old 07-17-2014, 03:12 PM   #12
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 3,943

Rep: Reputation: 1719Reputation: 1719Reputation: 1719Reputation: 1719Reputation: 1719Reputation: 1719Reputation: 1719Reputation: 1719Reputation: 1719Reputation: 1719Reputation: 1719
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.
 
1 members found this post helpful.
Old 07-17-2014, 03:59 PM   #13
michaelk
Moderator
 
Registered: Aug 2002
Posts: 17,236

Rep: Reputation: 2217Reputation: 2217Reputation: 2217Reputation: 2217Reputation: 2217Reputation: 2217Reputation: 2217Reputation: 2217Reputation: 2217Reputation: 2217Reputation: 2217
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.
 
Old 07-17-2014, 04:26 PM   #14
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,355

Rep: Reputation: 1509Reputation: 1509Reputation: 1509Reputation: 1509Reputation: 1509Reputation: 1509Reputation: 1509Reputation: 1509Reputation: 1509Reputation: 1509Reputation: 1509
Quote:
Originally Posted by rknichols View Post
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.
 
Old 07-17-2014, 11:13 PM   #15
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 3,943

Rep: Reputation: 1719Reputation: 1719Reputation: 1719Reputation: 1719Reputation: 1719Reputation: 1719Reputation: 1719Reputation: 1719Reputation: 1719Reputation: 1719Reputation: 1719
Quote:
Originally Posted by ntubski View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
manipulating locate (mlocate, slocate) behaviour ajaxStardust Linux - General 4 09-12-2012 08:17 PM
locate: can not open `/var/lib/mlocate/mlocate.db': No such file or directory BallsOfSteel Linux - Newbie 4 12-11-2010 08:30 AM
Apache not serving newly added files or php. theboomboomcars Linux - Server 4 08-16-2008 12:38 PM
Bash: keeping track of newly added files madtinkerer Programming 5 09-13-2006 09:30 AM
How to add an existing linux on a newly added disk to grub ? glenn69 Linux - Newbie 1 10-07-2004 09:16 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration