Why is the output of this find -newermt command apparently not in order?Ubuntu server terminal?How to rebuild fstab automaticallyWhat does this “find” command do?Filter the output of find commandWhat would this command do: “find . -ls ( pattern )”?Unable to fix - unmet dependencies and low file system root spacewhat does this command do?find command with optionsWhat's wrong with this 'find' command?

Why didn't Thatcher give Hong Kong to Taiwan?

"Practice makes perfect" and "c'est en forgeant qu'on devient forgeron"

What are ways to record who took the pictures if a camera is used by multiple people?

Can a system of three stars exist?

Does the telecom provider need physical access to the SIM card to clone it?

The 7-numbers crossword

Blender - Alpha is Luminance equivalent

Can my UK debt be collected because I have to return to US?

Can a country avoid prosecution for crimes against humanity by denying it happened?

Is Borg adaptation only temporary?

How would a disabled person earn their living in a medieval-type town?

Calculate Landau's function

Could a simple hospital oxygen mask protect from aerosol poison?

Are there balance issues when allowing attack of opportunity against any creature?

When you have to wait for a short time

Punishment in pacifist society

How are the cards determined in an incomplete deck of many things?

Killing task by name - start menu shortcut

Pandas transform inconsistent behavior for list

Given a specific computer system, is it possible to estimate the actual precise run time of a piece of Assembly code

To minimize the Hausdorff distance between convex polygonal regions

How to have the "Restore Missing Files" function from Nautilus without installing Nautilus?

Correct way of simplifying the result of an integral

Can UV radiation be safe for the skin?



Why is the output of this find -newermt command apparently not in order?


Ubuntu server terminal?How to rebuild fstab automaticallyWhat does this “find” command do?Filter the output of find commandWhat would this command do: “find . -ls ( pattern )”?Unable to fix - unmet dependencies and low file system root spacewhat does this command do?find command with optionsWhat's wrong with this 'find' command?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








4















When I run



touch a.txt && sleep 0.1 && 
touch b.txt && sleep 0.1 &&
touch c.txt && sleep 0.1 &&
touch d.txt && sleep 0.1 &&
touch e.txt && sleep 0.1 &&
touch f.txt && sleep 0.1 &&
find -newermt "1 sec ago"


the listing doesn't seem to be in order.



$ touch a.txt && sleep 0.1 && 
> touch b.txt && sleep 0.1 &&
> touch c.txt && sleep 0.1 &&
> touch d.txt && sleep 0.1 &&
> touch e.txt && sleep 0.1 &&
> touch f.txt && sleep 0.1 &&
> find -newermt "1 sec ago"
./d.txt
./f.txt
./a.txt
./c.txt
./b.txt
./e.txt
$


The order is reproducible. But why is the order the way it is? I know I can sort the output but the order of the default output just seems odd.



By the way, the same order is generated if -printf '%T@ %pn' is used:



$ touch a.txt && sleep 0.1 && 
> touch b.txt && sleep 0.1 &&
> touch c.txt && sleep 0.1 &&
> touch d.txt && sleep 0.1 &&
> touch e.txt && sleep 0.1 &&
> touch f.txt && sleep 0.1 &&
> find -newermt "1 sec ago" -type f -printf '%T@ %pn'
1567346420.7185077410 ./d.txt
1567346420.9305093600 ./f.txt
1567346420.3905052190 ./a.txt
1567346420.6065068740 ./c.txt
1567346420.5025060780 ./b.txt
1567346420.8225085330 ./e.txt
$



$ df -Th
Filesystem Type Size Used Avail Use% Mounted on
udev devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs tmpfs 785M 1.7M 784M 1% /run
/dev/sda6 ext4 288G 99G 175G 37% /
tmpfs tmpfs 3.9G 39M 3.8G 1% /dev/shm
tmpfs tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1 vfat 496M 39M 458M 8% /boot/efi
tmpfs tmpfs 785M 0 785M 0% /run/user/118
tmpfs tmpfs 785M 28K 785M 1% /run/user/1000
$


The filesystem is the default, ext4.




The shell from which these commands were run is bash:



$ bash --version
GNU bash, version 4.4.20(1)-release (x86_64-pc-linux-gnu)









share|improve this question





















  • 2





    They are returned in the order provided by the glibc readdir() function I think (which may in turn depend on the filesystem on which the files reside). Further reading: Does readdir() guarantee an order?

    – steeldriver
    9 hours ago











  • Yes, the filesystem is ext4, which according to a comment in your link specifically mentions ext4 as not following any particular order.

    – DK Bose
    9 hours ago

















4















When I run



touch a.txt && sleep 0.1 && 
touch b.txt && sleep 0.1 &&
touch c.txt && sleep 0.1 &&
touch d.txt && sleep 0.1 &&
touch e.txt && sleep 0.1 &&
touch f.txt && sleep 0.1 &&
find -newermt "1 sec ago"


the listing doesn't seem to be in order.



$ touch a.txt && sleep 0.1 && 
> touch b.txt && sleep 0.1 &&
> touch c.txt && sleep 0.1 &&
> touch d.txt && sleep 0.1 &&
> touch e.txt && sleep 0.1 &&
> touch f.txt && sleep 0.1 &&
> find -newermt "1 sec ago"
./d.txt
./f.txt
./a.txt
./c.txt
./b.txt
./e.txt
$


The order is reproducible. But why is the order the way it is? I know I can sort the output but the order of the default output just seems odd.



By the way, the same order is generated if -printf '%T@ %pn' is used:



$ touch a.txt && sleep 0.1 && 
> touch b.txt && sleep 0.1 &&
> touch c.txt && sleep 0.1 &&
> touch d.txt && sleep 0.1 &&
> touch e.txt && sleep 0.1 &&
> touch f.txt && sleep 0.1 &&
> find -newermt "1 sec ago" -type f -printf '%T@ %pn'
1567346420.7185077410 ./d.txt
1567346420.9305093600 ./f.txt
1567346420.3905052190 ./a.txt
1567346420.6065068740 ./c.txt
1567346420.5025060780 ./b.txt
1567346420.8225085330 ./e.txt
$



$ df -Th
Filesystem Type Size Used Avail Use% Mounted on
udev devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs tmpfs 785M 1.7M 784M 1% /run
/dev/sda6 ext4 288G 99G 175G 37% /
tmpfs tmpfs 3.9G 39M 3.8G 1% /dev/shm
tmpfs tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1 vfat 496M 39M 458M 8% /boot/efi
tmpfs tmpfs 785M 0 785M 0% /run/user/118
tmpfs tmpfs 785M 28K 785M 1% /run/user/1000
$


The filesystem is the default, ext4.




The shell from which these commands were run is bash:



$ bash --version
GNU bash, version 4.4.20(1)-release (x86_64-pc-linux-gnu)









share|improve this question





















  • 2





    They are returned in the order provided by the glibc readdir() function I think (which may in turn depend on the filesystem on which the files reside). Further reading: Does readdir() guarantee an order?

    – steeldriver
    9 hours ago











  • Yes, the filesystem is ext4, which according to a comment in your link specifically mentions ext4 as not following any particular order.

    – DK Bose
    9 hours ago













4












4








4








When I run



touch a.txt && sleep 0.1 && 
touch b.txt && sleep 0.1 &&
touch c.txt && sleep 0.1 &&
touch d.txt && sleep 0.1 &&
touch e.txt && sleep 0.1 &&
touch f.txt && sleep 0.1 &&
find -newermt "1 sec ago"


the listing doesn't seem to be in order.



$ touch a.txt && sleep 0.1 && 
> touch b.txt && sleep 0.1 &&
> touch c.txt && sleep 0.1 &&
> touch d.txt && sleep 0.1 &&
> touch e.txt && sleep 0.1 &&
> touch f.txt && sleep 0.1 &&
> find -newermt "1 sec ago"
./d.txt
./f.txt
./a.txt
./c.txt
./b.txt
./e.txt
$


The order is reproducible. But why is the order the way it is? I know I can sort the output but the order of the default output just seems odd.



By the way, the same order is generated if -printf '%T@ %pn' is used:



$ touch a.txt && sleep 0.1 && 
> touch b.txt && sleep 0.1 &&
> touch c.txt && sleep 0.1 &&
> touch d.txt && sleep 0.1 &&
> touch e.txt && sleep 0.1 &&
> touch f.txt && sleep 0.1 &&
> find -newermt "1 sec ago" -type f -printf '%T@ %pn'
1567346420.7185077410 ./d.txt
1567346420.9305093600 ./f.txt
1567346420.3905052190 ./a.txt
1567346420.6065068740 ./c.txt
1567346420.5025060780 ./b.txt
1567346420.8225085330 ./e.txt
$



$ df -Th
Filesystem Type Size Used Avail Use% Mounted on
udev devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs tmpfs 785M 1.7M 784M 1% /run
/dev/sda6 ext4 288G 99G 175G 37% /
tmpfs tmpfs 3.9G 39M 3.8G 1% /dev/shm
tmpfs tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1 vfat 496M 39M 458M 8% /boot/efi
tmpfs tmpfs 785M 0 785M 0% /run/user/118
tmpfs tmpfs 785M 28K 785M 1% /run/user/1000
$


The filesystem is the default, ext4.




The shell from which these commands were run is bash:



$ bash --version
GNU bash, version 4.4.20(1)-release (x86_64-pc-linux-gnu)









share|improve this question
















When I run



touch a.txt && sleep 0.1 && 
touch b.txt && sleep 0.1 &&
touch c.txt && sleep 0.1 &&
touch d.txt && sleep 0.1 &&
touch e.txt && sleep 0.1 &&
touch f.txt && sleep 0.1 &&
find -newermt "1 sec ago"


the listing doesn't seem to be in order.



$ touch a.txt && sleep 0.1 && 
> touch b.txt && sleep 0.1 &&
> touch c.txt && sleep 0.1 &&
> touch d.txt && sleep 0.1 &&
> touch e.txt && sleep 0.1 &&
> touch f.txt && sleep 0.1 &&
> find -newermt "1 sec ago"
./d.txt
./f.txt
./a.txt
./c.txt
./b.txt
./e.txt
$


The order is reproducible. But why is the order the way it is? I know I can sort the output but the order of the default output just seems odd.



By the way, the same order is generated if -printf '%T@ %pn' is used:



$ touch a.txt && sleep 0.1 && 
> touch b.txt && sleep 0.1 &&
> touch c.txt && sleep 0.1 &&
> touch d.txt && sleep 0.1 &&
> touch e.txt && sleep 0.1 &&
> touch f.txt && sleep 0.1 &&
> find -newermt "1 sec ago" -type f -printf '%T@ %pn'
1567346420.7185077410 ./d.txt
1567346420.9305093600 ./f.txt
1567346420.3905052190 ./a.txt
1567346420.6065068740 ./c.txt
1567346420.5025060780 ./b.txt
1567346420.8225085330 ./e.txt
$



$ df -Th
Filesystem Type Size Used Avail Use% Mounted on
udev devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs tmpfs 785M 1.7M 784M 1% /run
/dev/sda6 ext4 288G 99G 175G 37% /
tmpfs tmpfs 3.9G 39M 3.8G 1% /dev/shm
tmpfs tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1 vfat 496M 39M 458M 8% /boot/efi
tmpfs tmpfs 785M 0 785M 0% /run/user/118
tmpfs tmpfs 785M 28K 785M 1% /run/user/1000
$


The filesystem is the default, ext4.




The shell from which these commands were run is bash:



$ bash --version
GNU bash, version 4.4.20(1)-release (x86_64-pc-linux-gnu)






command-line files ext4 find






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 8 hours ago









Eliah Kagan

89.6k23 gold badges249 silver badges393 bronze badges




89.6k23 gold badges249 silver badges393 bronze badges










asked 10 hours ago









DK BoseDK Bose

18.9k12 gold badges54 silver badges107 bronze badges




18.9k12 gold badges54 silver badges107 bronze badges










  • 2





    They are returned in the order provided by the glibc readdir() function I think (which may in turn depend on the filesystem on which the files reside). Further reading: Does readdir() guarantee an order?

    – steeldriver
    9 hours ago











  • Yes, the filesystem is ext4, which according to a comment in your link specifically mentions ext4 as not following any particular order.

    – DK Bose
    9 hours ago












  • 2





    They are returned in the order provided by the glibc readdir() function I think (which may in turn depend on the filesystem on which the files reside). Further reading: Does readdir() guarantee an order?

    – steeldriver
    9 hours ago











  • Yes, the filesystem is ext4, which according to a comment in your link specifically mentions ext4 as not following any particular order.

    – DK Bose
    9 hours ago







2




2





They are returned in the order provided by the glibc readdir() function I think (which may in turn depend on the filesystem on which the files reside). Further reading: Does readdir() guarantee an order?

– steeldriver
9 hours ago





They are returned in the order provided by the glibc readdir() function I think (which may in turn depend on the filesystem on which the files reside). Further reading: Does readdir() guarantee an order?

– steeldriver
9 hours ago













Yes, the filesystem is ext4, which according to a comment in your link specifically mentions ext4 as not following any particular order.

– DK Bose
9 hours ago





Yes, the filesystem is ext4, which according to a comment in your link specifically mentions ext4 as not following any particular order.

– DK Bose
9 hours ago










1 Answer
1






active

oldest

votes


















3















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.






share|improve this answer

























  • • I get the same order using find -mmin -1 of course with some additional interspersed entries. • All the touched files are in the same directory. • I also ran the same code from a folder which had no lower subfolders, ~/Public: same order.

    – DK Bose
    7 hours ago











  • I also tried from ~/Videos: exactly the same order. So there seems to be some method in the madness?

    – DK Bose
    7 hours ago











  • @DKBose Yes, the order is unspecified, not random. It depends on the data structures used by the filesystem and the implementation details of the filesystem driver, and you cannot rely on it even for separate traversals of the same files, but it is not surprising that it's sometimes stable and that it follows or appears to follow a discernible pattern.

    – Eliah Kagan
    7 hours ago











  • Yes, and as steeldriver's link suggests, it's better to sort the output in any case.

    – DK Bose
    7 hours ago













Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1170000%2fwhy-is-the-output-of-this-find-newermt-command-apparently-not-in-order%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3















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.






share|improve this answer

























  • • I get the same order using find -mmin -1 of course with some additional interspersed entries. • All the touched files are in the same directory. • I also ran the same code from a folder which had no lower subfolders, ~/Public: same order.

    – DK Bose
    7 hours ago











  • I also tried from ~/Videos: exactly the same order. So there seems to be some method in the madness?

    – DK Bose
    7 hours ago











  • @DKBose Yes, the order is unspecified, not random. It depends on the data structures used by the filesystem and the implementation details of the filesystem driver, and you cannot rely on it even for separate traversals of the same files, but it is not surprising that it's sometimes stable and that it follows or appears to follow a discernible pattern.

    – Eliah Kagan
    7 hours ago











  • Yes, and as steeldriver's link suggests, it's better to sort the output in any case.

    – DK Bose
    7 hours ago















3















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.






share|improve this answer

























  • • I get the same order using find -mmin -1 of course with some additional interspersed entries. • All the touched files are in the same directory. • I also ran the same code from a folder which had no lower subfolders, ~/Public: same order.

    – DK Bose
    7 hours ago











  • I also tried from ~/Videos: exactly the same order. So there seems to be some method in the madness?

    – DK Bose
    7 hours ago











  • @DKBose Yes, the order is unspecified, not random. It depends on the data structures used by the filesystem and the implementation details of the filesystem driver, and you cannot rely on it even for separate traversals of the same files, but it is not surprising that it's sometimes stable and that it follows or appears to follow a discernible pattern.

    – Eliah Kagan
    7 hours ago











  • Yes, and as steeldriver's link suggests, it's better to sort the output in any case.

    – DK Bose
    7 hours ago













3














3










3









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.






share|improve this answer













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.







share|improve this answer












share|improve this answer



share|improve this answer










answered 8 hours ago









Eliah KaganEliah Kagan

89.6k23 gold badges249 silver badges393 bronze badges




89.6k23 gold badges249 silver badges393 bronze badges















  • • I get the same order using find -mmin -1 of course with some additional interspersed entries. • All the touched files are in the same directory. • I also ran the same code from a folder which had no lower subfolders, ~/Public: same order.

    – DK Bose
    7 hours ago











  • I also tried from ~/Videos: exactly the same order. So there seems to be some method in the madness?

    – DK Bose
    7 hours ago











  • @DKBose Yes, the order is unspecified, not random. It depends on the data structures used by the filesystem and the implementation details of the filesystem driver, and you cannot rely on it even for separate traversals of the same files, but it is not surprising that it's sometimes stable and that it follows or appears to follow a discernible pattern.

    – Eliah Kagan
    7 hours ago











  • Yes, and as steeldriver's link suggests, it's better to sort the output in any case.

    – DK Bose
    7 hours ago

















  • • I get the same order using find -mmin -1 of course with some additional interspersed entries. • All the touched files are in the same directory. • I also ran the same code from a folder which had no lower subfolders, ~/Public: same order.

    – DK Bose
    7 hours ago











  • I also tried from ~/Videos: exactly the same order. So there seems to be some method in the madness?

    – DK Bose
    7 hours ago











  • @DKBose Yes, the order is unspecified, not random. It depends on the data structures used by the filesystem and the implementation details of the filesystem driver, and you cannot rely on it even for separate traversals of the same files, but it is not surprising that it's sometimes stable and that it follows or appears to follow a discernible pattern.

    – Eliah Kagan
    7 hours ago











  • Yes, and as steeldriver's link suggests, it's better to sort the output in any case.

    – DK Bose
    7 hours ago
















• I get the same order using find -mmin -1 of course with some additional interspersed entries. • All the touched files are in the same directory. • I also ran the same code from a folder which had no lower subfolders, ~/Public: same order.

– DK Bose
7 hours ago





• I get the same order using find -mmin -1 of course with some additional interspersed entries. • All the touched files are in the same directory. • I also ran the same code from a folder which had no lower subfolders, ~/Public: same order.

– DK Bose
7 hours ago













I also tried from ~/Videos: exactly the same order. So there seems to be some method in the madness?

– DK Bose
7 hours ago





I also tried from ~/Videos: exactly the same order. So there seems to be some method in the madness?

– DK Bose
7 hours ago













@DKBose Yes, the order is unspecified, not random. It depends on the data structures used by the filesystem and the implementation details of the filesystem driver, and you cannot rely on it even for separate traversals of the same files, but it is not surprising that it's sometimes stable and that it follows or appears to follow a discernible pattern.

– Eliah Kagan
7 hours ago





@DKBose Yes, the order is unspecified, not random. It depends on the data structures used by the filesystem and the implementation details of the filesystem driver, and you cannot rely on it even for separate traversals of the same files, but it is not surprising that it's sometimes stable and that it follows or appears to follow a discernible pattern.

– Eliah Kagan
7 hours ago













Yes, and as steeldriver's link suggests, it's better to sort the output in any case.

– DK Bose
7 hours ago





Yes, and as steeldriver's link suggests, it's better to sort the output in any case.

– DK Bose
7 hours ago

















draft saved

draft discarded
















































Thanks for contributing an answer to Ask Ubuntu!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1170000%2fwhy-is-the-output-of-this-find-newermt-command-apparently-not-in-order%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

François Viète Contents Biography Work and thought Bibliography See also Notes Further reading External links Navigation menup. 21Google Bookspp. 75–77Google BooksDe thou (from University of Saint Andrews)ArchivedGoogle BooksGoogle BooksGoogle BooksGoogle booksGoogle Bookscc-parthenay.frL'histoire universelle (fr)Universal History (en)ArchivedAdsabs.harvard.eduPagesperso-orange.frArchive.orgChikara Sasaki. Descartes' mathematical thought p.259Google BooksGoogle BooksGoogle Bookspp. 152 and onwardGoogle BooksGoogle BooksScribd.comGoogle Books1257-7979Google BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGallica.bnf.frGoogle BooksGoogle Books"François Viète"Francois Viète: Father of Modern Algebraic NotationThe Lawyer and the GamblerAbout TarporleySite de Jean-Paul GuichardL'algèbre nouvelle"About the Harmonicon"cb120511976(data)1188044800000 0001 0913 5903n82164680ola2013766880073431702w6vt1sb70287374827140948071409480