0

How is it possible for updatedb to run very fast by avoiding doing full disk scans? Since mtime of parent folder is not affected by files in subfolders.

In Why does the updatedb program run so fast?

@hugomg I don't think it actually does. It should only change the mtime of its immediate parent. – @Kusalananda

I searched but cannot find the answer.

1
  • Perhaps updatedb is misconfigured at your site, and isn't indexing what you think. Read man updatedb and look at how you call updatedb on your system, start with less /etc/crontab.
    – waltinator
    Aug 31, 2023 at 18:05

1 Answer 1

1

When updatedb is run for the first time, there is no way to avoid scanning every directory.

But on subsequent scans, if a directory's mtime is unchanged from its old entry in the locate database, there are no new files and no new subdirectories - so instead of scanning the complete directory, updatedb can just use its old database to know the names of any existing sub-directories. So it can proceed directly to checking the mtimes of those subdirectories, and apply the same rule to them.

In other words, if a filesystem is unchanged since the previous updatedb run, the only thing updatedb needs to do to confirm it is to stat() each directory entry it already has in its database, and check that its mtime remains unchanged.

Only directories whose mtime has changed will need a full directory scan: that will uncover any new, renamed or deleted files, links and sub-directories. If new/renamed sub-directories are found, they will need to be fully scanned too.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .