# chmod: read the permission string and change it

Published: 2026-11-30

Rights: original
Source: https://kairos-2z6s.onrender.com/res/chmod-basics-full-en
chmod sets read, write and execute bits on files and directories for owner, group and others, in symbolic or numeric form. In the recorded run, as a non-root user (uid 1000), reading d/x fails with exit status 1 when the directory has mode 644 and works with mode 755; the error line is "cat: d/x: Permission denied".

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-19-A, TE-19-B and TE-19-C. The expected non-zero exit is TE-19-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-19-A: numeric mode sets exact bits; a directory without execute permission cannot be traversed by a normal user

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

```bash
mkdir -p d; printf 'x\n' > f.txt; printf 'inner\n' > d/x
```

Command:

```bash
chmod 644 f.txt; echo file=$(stat -c %a f.txt); chmod 644 d; cat d/x 2>&1; echo rc_without_x=$?; chmod 755 d; cat d/x; echo rc_with_x=$?; id -u
```

Recorded output:

```
file=644
cat: d/x: Permission denied
rc_without_x=1
inner
rc_with_x=0
1000
```

### TE-19-B: chmod u+x adds the execute bit for the owner to a file set to mode 600

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

```bash
printf 'x\n' > f.txt
```

Command:

```bash
chmod 600 f.txt; stat -c %a f.txt; chmod u+x f.txt; stat -c %a f.txt
```

Recorded output:

```
600
700
```

Exit status: 0. This status and the output match what was written before the run.

### TE-19-C: expected non-zero exit: chmod rejects a numeric mode that contains the digit 9

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

```bash
printf 'x\n' > f.txt
```

Command:

```bash
chmod 999 f.txt
```

Recorded output: none, standard output was empty.

Standard error from the same run:

```
chmod: invalid mode: ‘999’
Try 'chmod --help' for more information.
```

Exit status: 1. This status and the output match what was written before the run.

## Reading the recorded output

The first line, file=644, is the mode that stat reports for f.txt after chmod 644. Next, the same user tried to read d/x while the directory d had mode 644, which has no execute bit. The read failed with Permission denied and status 1. After chmod 755 on the directory, the same read printed inner and the status was 0. The last output line shows that this user has uid 1000. In this run the only change between failure and success was the mode of the directory d.

TE-19-B: stat printed 600 after chmod 600, and 700 after chmod u+x on the same file. TE-19-C: chmod 999 f.txt exited with status 1. Standard error holds chmod: invalid mode: ‘999’ and a line that starts with Try 'chmod --help'.

## Limits

Traditional rwx model only; directory `x` means traverse; ACLs and special bits are out of scope.

## Source

- https://www.gnu.org/software/coreutils/manual/html_node/File-permissions.html

## Evidence

- `TE-19-A`: numeric mode sets exact bits; a directory without execute permission cannot be traversed by a normal user

- 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-19-A` | numeric mode sets exact bits; a directory without execute permission cannot be traversed by a normal user | 0 | PASS | `06c8bb5f0082` |
| `TE-19-B` | chmod u+x adds the execute bit for the owner to a file set to mode 600 | 0 | PASS | `673fc191475c` |
| `TE-19-C` | expected non-zero exit: chmod rejects a numeric mode that contains the digit 9 | 1 | PASS | `04025b7c072e` |

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
- [xargs: turn lines of input into command arguments](https://kairos-2z6s.onrender.com/res/xargs-basics-full-en)
- [grep: search text, with the options worth knowing](https://kairos-2z6s.onrender.com/res/grep-basics-full-en)
- [Bash exit codes: 0 is success, and && and || use it](https://kairos-2z6s.onrender.com/res/bash-exit-codes-full-en)
- [Create and switch to a new Git branch](https://kairos-2z6s.onrender.com/res/create-and-switch-git-branch-en)
- [Bash variables, loops and if: the basics](https://kairos-2z6s.onrender.com/res/bash-variables-loops-full-en)
- [curl basics: fetch a page, save it, read the status code](https://kairos-2z6s.onrender.com/res/curl-basics-full-en)
