---
name: list
description: The entries beneath a directory, sorted bytewise, depth-bounded and capped, as NDJSON records; links listed and never followed, and no verb but reading.
---

# list 0.1.0

The entries beneath a directory, sorted bytewise, depth-bounded and capped, as NDJSON records; links listed and never followed, and no verb but reading.

```
list [--root DIR] [--depth N] [--max-entries N] [--skip N] [--long] [--format ndjson|text] [DIR...]
```

## Output

NDJSON: one JSON object per line, schema `list.v1`. The last line is a record with `"type":"end"`; **a stream without one was cut short and must be treated as truncated**. `complete` is false when the tool stopped early. Errors are records with `"type":"error"`.

An error is `{code, rule, message, hint, repair, detail}`. Match on `rule`, not on `message`. When `repair` is `{"kind":"retry","argv":[...]}` the argv can be run as it stands; it never widens what the tool may touch.

`--format text` is for a person and is lossy; do not parse it.

## Flags

- `--root <path>`: resolve every DIR relative to this directory and refuse paths outside it
- `--depth <nat>` (`-d`): how many levels to descend: 1 is the directory's own entries (ceiling 64) Default `1`.
- `--max-entries <nat>` (`-n`): stop after this many entries in total, and report truncated with a next cursor (ceiling 1000000) Default `10000`.
- `--skip <nat>`: skip this many entries before reporting any (the next cursor of a truncated run) Default `0`.
- `--long` (`-l`): add each entry's size in bytes and modification time in seconds
- `--format <choice:ndjson/text>`: ndjson for a program, text (one path a line, a directory ending in /) for a person Default `ndjson`.

An unknown flag is refused (`args.unknown-flag`), never ignored. POSIX spellings are not promised.

## Guarantees

- **deterministic**: the same input gives byte-identical output, through a pipe, a file or a terminal (M2)
- **idempotent**: running it twice leaves the same state as once (M7 for the writers, and a reader changes nothing)
- **concurrency**: read-only; it never writes.

## Exit codes

- `0` SUCCESS: what was asked was done; zero matches is success
- `2` INVALID_ARGS: the invocation is malformed or names something of the wrong kind; nothing was read
- `3` NOT_FOUND: a named input does not exist
- `4` PERMISSION_DENIED: the operating system refused, or the tool's own confinement did
- `132`: the tool trapped. A bug in the tool; there is no JSON.
- `141`: the reader closed the pipe.

## Rules

- `args.unknown-flag` (exit 2): a flag that is not in the tool's table
- `args.missing-value` (exit 2): a flag that takes a value was given none
- `args.bad-value` (exit 2): a flag's value is not of the flag's kind
- `args.unexpected-value` (exit 2): a flag that takes no value was given one
- `args.duplicate-flag` (exit 2): the same flag was given twice
- `path.empty` (exit 2): an empty path
- `path.dotdot` (exit 2): a path with a `..` component
- `path.absolute` (exit 2): an absolute path where one relative to --root is wanted
- `path.outside-root` (exit 4): an absolute path that is not under --root
- `path.too-long` (exit 2): a path longer than 4096 bytes
- `path.symlink` (exit 4): a path that runs through a symbolic link, which the tool does not follow
- `io.not-found` (exit 3): a named input does not exist
- `io.not-a-directory` (exit 3): a path runs through something that is not a directory
- `io.permission-denied` (exit 4): the operating system refused access

## Authority

What the compiler says this program can reach (`cancho authority`), embedded at build time:

```json
{"bounded":true,"unbounded_by":[],"effects":["args","dir_read","err_write","fs_read","heap","io_write"],"labels":[{"name":"args","argument":null,"bounded":true},{"name":"dir_read","argument":null,"bounded":true},{"name":"err_write","argument":null,"bounded":true},{"name":"fs_read","argument":"","bounded":true},{"name":"heap","argument":null,"bounded":true},{"name":"io_write","argument":null,"bounded":true}],"never_touches":["the network","signals","other programs","foreign code"],"foreign_symbols":[],"pure":["alphabet","authority","built","bytes","catalogue","code_meaning","code_name","compare","compiler","count","count","count","count","count_byte","decode","default_of","digit_of","distance","emits","enotdir","entries","entry","entry","entry_at","entry_end","entry_in","equal","err_control","err_depth","err_end","err_escape","err_full","err_number","err_syntax","err_trailing","err_utf8","escape_width","exit_code","exit_in_entry","exit_of_in","expected","failed","field","field_of","field_of","find","find_in","finish","flag_table","full","get$int","guarantee_keys","guarantees_has","has","has_dotdot","hex4","hex_digit","hex_value","in_choice","in_range","index_of","index_of_short","io_rule","is_ascii","is_digit","is_digit","is_flag","is_hex","is_loop","is_named","is_tail","is_utf8","is_valid","is_ws","item","kind","kind_directory","kind_file","kind_link","kind_name","kind_of","kind_other","kind_unknown","lead_bits","longest","max_depth","message_of","most_depth","most_entries","name","name_of","nearest","not_after","nth","ok","operand_count","operand_index","parse_nat","plain_byte","repairable_in","rule_of","scan_for","schema","second_range","sentences","shell_builtin","shown","size","size$int","slash","start","starts_with","string_end","summary_in","takes_value","tape_len","tool","truncated","under","valid","value_index","width_of"],"folded_operators":29,"folded_calls":0,"functions":223}
```

The row names *kinds* of access, not *extent*: a path from the command line is checked at run time, so it reads `fs_read("")`. Symlinks are followed.
