---
name: move
description: Rename a file or directory in place, never over an existing name (the kernel refuses it, even if another process creates it mid-move); locked, atomic, idempotent with --if-sha256, with --dry-run. One directory: a move to another is not offered. With --remove and --if-sha256, a file is removed by renaming it to a tombstone, and nothing is deleted.
---

# move 0.1.0

Rename a file or directory in place, never over an existing name (the kernel refuses it, even if another process creates it mid-move); locked, atomic, idempotent with --if-sha256, with --dry-run. One directory: a move to another is not offered. With --remove and --if-sha256, a file is removed by renaming it to a tombstone, and nothing is deleted.

```
move [--root DIR] [--if-sha256 HEX] [--dry-run] [--format json|text] PATH NEWNAME | move --remove --if-sha256 HEX [--root DIR] [--dry-run] PATH
```

## Output

One JSON object on one line, schema `move.v1`: `{ok, command, schema, data, error, errors, meta}`. `ok` is false exactly when `errors` is non-empty; `error` is the first.

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 PATH relative to this directory and refuse paths outside it
- `--if-sha256 <hex64>`: the file's current content must hash to this SHA-256, and a retry that already landed then answers changed: false
- `--remove`: remove the file by renaming it to its tombstone .NAME.removed-HASH8 (needs --if-sha256, takes no NEWNAME, and nothing is deleted)
- `--dry-run`: check everything and report planned_actions, exit 9, change nothing
- `--format <choice:json/text>`: json for a program, text for a person Default `json`.

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)
- **atomic**: a reader never sees a partial target: the new content is a synced temporary renamed over it (M7)
- **dry_run**: --dry-run reports what an apply would do and makes no mutating system call (M7, under strace)
- **concurrency**: locked; of writers racing with the same precondition, exactly one wins and the others are refused, so re-read and retry.

## Exit codes

- `0` SUCCESS: what was asked was done; zero matches is success
- `1` GENERAL_ERROR: the operating system failed mid-operation, or the tool caught a bug in itself
- `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
- `5` CONFLICT: state is not what the caller said it would be
- `8` PRECONDITION_FAILED: the answer is no, or a limit was reached
- `9` DRY_RUN: a --dry-run completed; planned_actions lists what an apply would do
- `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
- `args.required-flag` (exit 2): a flag the tool needs was not given
- `args.missing-operand` (exit 2): an operand the tool needs was not given
- `args.too-many-operands` (exit 2): more operands than the tool takes
- `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
- `path.bad-name` (exit 2): a new name that is not one plain name in the same directory
- `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.is-a-directory` (exit 2): a directory where a file is wanted
- `io.permission-denied` (exit 4): the operating system refused access
- `io.read-failed` (exit 1): the operating system failed a read
- `io.write-failed` (exit 1): the operating system failed a write, or a write was short
- `precondition.hash-mismatch` (exit 5): the file's hash is not the one --if-sha256 named
- `conflict.exists` (exit 5): --create was given and the path exists
- `conflict.locked` (exit 5): another writer holds the path's lock
- `io.rename-unsupported` (exit 8): the filesystem cannot refuse an existing name atomically, so move did not rename

## Authority

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

```json
{"bounded":true,"unbounded_by":[],"effects":["args","dir_read","dir_write","err_write","file_read","file_write","fs_read","heap","io_write"],"labels":[{"name":"args","argument":null,"bounded":true},{"name":"dir_read","argument":null,"bounded":true},{"name":"dir_write","argument":null,"bounded":true},{"name":"err_write","argument":null,"bounded":true},{"name":"file_read","argument":null,"bounded":true},{"name":"file_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","bad_name","built","bytes","catalogue","code_meaning","code_name","compiler","count","count","count","count_byte","decode","default_of","digit_of","discard","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","field","field_of","field_of","find","find_in","finish","first","flag_table","full","get$int","guarantee_keys","guarantees_has","has","has_dotdot","hex4","hex_digit","hex_digit","hex_value","in_choice","in_range","index_of","index_of_short","io_rule","is_ascii","is_digit","is_digit","is_directory_name","is_flag","is_hex","is_loop","is_named","is_tail","is_utf8","is_valid","is_ws","item","kind_directory","kind_file","kind_link","kind_name","kind_of","lead_bits","leaf","listed","longest","low_mask64","lshr64","mask32","max_depth","message_of","name_of","nearest","no_outcome","ok","operand_count","operand_index","parent_of","parse_nat","plain_byte","repairable_in","rotr64","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","under","update","valid","value_index","width_of","would_block"],"folded_operators":31,"folded_calls":0,"functions":248}
```

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.
