1

I have big directory tree of files. I often use the find command to locate something in that tree. The first time after a reboot it takes some time, but subsequent uses are almost instant. Obviously find uses some internal datastructure that it has to recreate after a reboot.

Is there a way to keep this datastructure between reboots?

additional info:

  • the root of the directory tree is always the same, but it is on another drive that is not always mounted
  • it has ~50000 files over ~2000 directories
  • i use the -iregex option for find

2 Answers 2

7

It's the kernel file system cache that makes a second find command so fast. As far as I can tell, there's no way to dump and restore the file system cache. If there would be, I'd expect it to be slower to first write the cache to disk and later reread it, than running the find command afresh.

4
  • You can prime the caché with ls -R / Jul 22, 2019 at 13:14
  • 3
    @ctrl-alt-delor there’s no ‘é’ in cache ;-). Jul 22, 2019 at 14:29
  • @StephenKitt But "caché" has a certain, umm, cachet... Jul 22, 2019 at 15:16
  • 1
    @Andrew you can’t sashay into my caché! Jul 22, 2019 at 15:33
2

If your directory tree is relatively static (i.e. files and directories are created or removed infrequently), rather than find, you might try using locate.

locate(1)                 General Commands Manual      locate(1)

NAME
       locate - find files by name

SYNOPSIS
       locate [OPTION]... PATTERN...

DESCRIPTION
       locate reads one or more databases prepared by updatedb(8)
       and writes file names matching at least one of the
       PATTERNs to standard output, one per line.

       If --regex is not specified, PATTERNs can contain globbing characters.
       If any PATTERN contains no globbing characters,
       locate behaves as if the pattern were *PATTERN*.

       By  default, locate does not check whether files found in database
       still exist (but it does require all parent directories to exist
       if the database was built with --require-visibility no).
       locate can  never  report  files created after the most recent
       update of the relevant database.
…
1
  • updatedb does what I want
    – chrm
    Aug 2, 2019 at 23:52

You must log in to answer this question.

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