# find: list files by name and sort the result

Published: 2026-11-30

Rights: original
Source: https://kairos-2z6s.onrender.com/res/find-basics-full-en
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.

(Test: 3 tests were run, TE-17-A, TE-17-B and TE-17-C. The expected non-zero exit is TE-17-C (exit status 1). Every row has a recorded log in the evidence archive. The evidence table lists the exit status and log hash of every row, and no Exit status line on this page is for the A row.)

### TE-17-A: find output order can vary; sort makes it deterministic

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
mkdir -p d; for n in c a b; do printf 'x\n' > d/$n.txt; done
```

Command:

```bash
find d -name '*.txt' | wc -l; find d -name '*.txt' | sort | head -3
```

Recorded output:

```
3
d/a.txt
d/b.txt
d/c.txt
```

### TE-17-B: find with a name pattern lists only the matching path

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
mkdir -p d; for n in c a b; do printf 'x\n' > d/$n.txt; done
```

Command:

```bash
find d -name 'a*.txt'
```

Recorded output:

```
d/a.txt
```

Exit 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:

```bash
find nosuchdir -name x
```

Recorded output: none, standard output was empty.

Standard error from the same run:

```
find: ‘nosuchdir’: No such file or directory
```

Exit 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

- https://www.gnu.org/software/findutils/manual/

## 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.

## Related guides
- [grep: search text, with the options worth knowing](https://kairos-2z6s.onrender.com/res/grep-basics-full-en)
- [find: -maxdepth, -type f and -size +1c narrow the result](https://kairos-2z6s.onrender.com/res/find-options-full-en)
- [diff: see what changed between two files](https://kairos-2z6s.onrender.com/res/diff-basics-full-en)
- [mkdir, cp, mv and rm: the basic file commands](https://kairos-2z6s.onrender.com/res/file-commands-full-en)
- [How to fix a Git merge conflict step by step](https://kairos-2z6s.onrender.com/res/fix-git-merge-conflict-en)
- [sed basics: replace text in a stream](https://kairos-2z6s.onrender.com/res/sed-basics-full-en)
