find: list files by name and sort the result
find lists files by name pattern; sort makes the order deterministic. The run shows only -name and the effect of sort.
Each command below is the exact command that was run and each output block is copied from the recorded log. Test ids, log hashes and exit statuses are in the evidence table.
TE-17-A: find output order can vary; sort makes it deterministic
Setup for this run, inside a throwaway directory (mktemp -d):
mkdir -p d; for n in c a b; do printf 'x\n' > d/$n.txt; doneCommand:
find d -name '*.txt' | wc -l; find d -name '*.txt' | sort | head -3Recorded output:
3
d/a.txt
d/b.txt
d/c.txtTE-17-B: find with a name pattern lists only the matching path
Setup for this run, inside a throwaway directory (mktemp -d):
mkdir -p d; for n in c a b; do printf 'x\n' > d/$n.txt; doneCommand:
find d -name 'a*.txt'Recorded output:
d/a.txtExit status: 0. This status and the output match what was written before the run.
TE-17-C: expected non-zero exit: find on a folder that does not exist prints an error and exits with status 1
No setup needed: the command below creates what it uses in the throwaway folder.
Command:
find nosuchdir -name xRecorded output: none, standard output was empty.
Standard error from the same run:
find: ‘nosuchdir’: No such file or directoryExit status: 1. This status and the output match what was written before the run.
TE-17-B: by the setup, d holds a.txt, b.txt and c.txt. find d -name 'a*.txt' printed d/a.txt only. TE-17-C: find nosuchdir -name x printed find: ‘nosuchdir’: No such file or directory to standard error and exited with status 1.
Limits
Only -name and the effect of sort are tested here. Filtering by type, size or depth, and actions such as -exec, are not tested on this page.
Source
Evidence
TE-17-A: find output order can vary; sort makes it deterministic
- logs: one recorded log for each row above
- Recorded on: Linux x86_64, kernel 7.3.4; bash 5.1.16; git 2.34.1; python 3.10.12; findutils 4.8.0; grep 3.7; sed 4.8; gawk 5.1.0; tar 1.34; curl 7.81.0. Locale C.UTF-8, TZ=UTC.
Evidence table
| Test | What it checks | Exit | Verdict | Log sha256 (first 12) | |---|---|---|---|---| | TE-17-A | find output order can vary; sort makes it deterministic | 0 | PASS | 72851a287951 | | TE-17-B | find with a name pattern lists only the matching path | 0 | PASS | d7e9d1307492 | | TE-17-C | expected non-zero exit: find on a folder that does not exist prints an error and exits with status 1 | 1 | PASS | 92d833aeb344 |
Every row has a recorded log holding the setup commands, the command, stdout, stderr, exit status and the final directory state. The first 12 characters of the log's sha256 are in the table.
All full guides: All guides