I noticed that when using find <dir> -depth for the first time on a directory, it consumes quite a lot of time, but the next times even when searching for a different pattern, it seems pretty fast.

Why is this and can this behavior even be further used to achieve better performance?


1 Answer 1


When you first type the find command, the operating system will have to get the subdirectories informations from the disk. The second time you type the same command, you get the data from the cache which is faster.

If you filter the output with different pattern, find will read each directory completely even if only some entries match the pattern. Then the cache will be full of information needed for other patterns.

However, if you use the system for a while, the cache memory could be used for other purposes… then the same find command may have to get the data back from the disk again and can be as slow as the first time. If you want to limit the risk of having the cache memory reused, you have to add memory.

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