Quantcast
Channel: Why is the output of this find -newermt command apparently not in order? - Ask Ubuntu
Viewing all articles
Browse latest Browse all 2

Answer by Eliah Kagan for Why is the output of this find -newermt command apparently not in order?

$
0
0

There are two important concepts here: -newerXY only affects which files are operated on and not the order in which they are operated on, the the order find discovers siblings is unspecified and in practice contingent on the implementation details of the filesystem driver.

-newerXY filters but it does not sort.

The -newermt predicate tests if files were modified more recently than the time you specify as its operand (1 sec ago in this case), filtering out those that are older. It does not affect the order in which find discovers files, nor does it affect the order in which actions (including the default -print action when no other action is supplied) are performed, which is the same as the order in which files are discovered. Since find performs actions on files in the order they are discovered and does not sort its output, newermt does not cause files to be sorted by their modification time.

All this applies equally to other forms of -newerXY.

Files in the same directory may be discovered in any order.

As for what the order of discovery is, as steeldriver says, there is no guaranteed order for this for files residing directly in the same directory. You may sometimes see files in the same order in similar situations and sometimes not, and there is no promise made about the order.

find operates recursively, walking the entire directory hierarchy from each of its starting points. (Ubuntu uses GNU find which treats the absence of a specified starting point, as in your example, as meaning to start from ..) Specifically, it performs a depth-first preorder traversal of one or more directory trees. It is possible to limit where in a tree it goes with the -maxdepth and -prune predicates, as well as to prevent it from selecting files based on where they are in the tree in various ways (including -mindepth), but otherwise it looks everywhere under its starting points.

This does imply some constraints on the order in which it discovers files. It cannot skip back and forth between files in different directories. If you give it a as a starting point, it may discover a/x/1 before or after a/x/2. If it finds a/y, it may appear either before or after a/x/y and a/x/2. This is all to say that entries residing immediately in the same directory may be processed in any order. But a/y will not appear between a/x/1 and a/x/2.


Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>