Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

order of files unix find on two directories with or command

Tags:

linux

bash

unix

What is the expected order of the files if one executes the following find command on Linux:

mkdir /tmp/dir1 /tmp/dir2
touch /tmp/dir1/1 /tmp/dir1/2 /tmp/dir2/1 /tmp/dir2/2 /tmp/dir2/3 /tmp/dir2/0
find /tmp/dir1 /tmp/dir2 -name 1 -or -name 0 -not -name 2

/tmp/dir1/1
/tmp/dir2/1
/tmp/dir2/0

Is it supposed to always give the results back from dir1 first, then dir2, or can the results be mixed in order?

like image 671
719016 Avatar asked Jul 17 '13 12:07

719016


1 Answers

The find command will search the directories in the order given. Since you said

find /tmp/dir1 /tmp/dir2 .....

it will always first find evrything that matches below /tmp/dir1, then /tmp/dir2.

Yet, subdirectories and files can, of course, appear in any order.

like image 67
Ingo Avatar answered Oct 05 '22 18:10

Ingo