# mkdir, cp, mv and rm: the basic file commands

Published: 2026-11-30

Rights: original
Source: https://kairos-2z6s.onrender.com/res/file-commands-full-en
mkdir, cp, mv and rm create, copy, move and delete files and directories. The commands here run in a throwaway directory.

> **Warning:** these commands delete and overwrite files. A deleted file does not go to a recycle bin. Run them only in a throwaway directory created with `mktemp -d`.

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-44-A, TE-44-B and TE-44-C. The expected non-zero exit is TE-44-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-44-A: mkdir/cp/mv/rm inside a throwaway directory, including recursive forms

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

```bash
mkdir -p box
```

Command:

```bash
mkdir -p box/a/b; echo m=$?; printf 'x\n' > box/a/f.txt; cp -r box/a box/copy; echo cp=$?; mv box/copy box/moved; echo mv=$?; rm -r box/moved; echo rm=$?; find box -type f | wc -l; rm -r box/a 2>/dev/null; echo gone=$([ -d box/a ] && echo no || echo yes)
```

Recorded output:

```
m=0
cp=0
mv=0
rm=0
1
gone=yes
```

### TE-44-B: cp copies a file and mv renames the copy

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

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

Command:

```bash
cp a.txt b.txt; mv b.txt c.txt; ls
```

Recorded output:

```
a.txt
c.txt
```

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

### TE-44-C: expected non-zero exit: cp of a file that does not exist is an error and creates nothing

No setup needed: the command below creates what it uses in the throwaway folder.

Command:

```bash
cp nosuch.txt b.txt; rc=$?; ls; exit $rc
```

Recorded output: none, standard output was empty.

Standard error from the same run:

```
cp: cannot stat 'nosuch.txt': No such file or directory
```

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

## Reading the recorded output

The first four lines are the exit statuses of mkdir, cp, mv and rm, in that order. Each printed 0. The next line, 1, is the count of regular files under box after the copy was moved to box/moved and removed with rm -r. The count 1 means one regular file is left under box; by the commands that is box/a/f.txt. The last line is printed after rm -r box/a and says the directory box/a is gone. The run does not print the directory tree itself, so it shows the file count and the final check, and no listing.

TE-44-B: by the setup, a.txt exists. cp made b.txt, mv renamed it to c.txt, and ls lists a.txt and c.txt. TE-44-C: cp nosuch.txt b.txt exited with status 1 and printed cp: cannot stat 'nosuch.txt': No such file or directory to standard error. ls printed nothing, so b.txt was not created.

## Limits

The commands here create, copy, move and delete files and directories inside a throwaway directory. A deleted file is not moved to a trash; the run only shows that the directory box/a no longer exists afterwards.

## Source

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

## Evidence

- `TE-44-A`: mkdir/cp/mv/rm inside a throwaway directory, including recursive forms

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


> **Warning:** this example is destructive. Run it only in a throwaway directory, not against real files.

## Evidence table

| Test | What it checks | Exit | Verdict | Log sha256 (first 12) |
|---|---|---|---|---|
| `TE-44-A` | mkdir/cp/mv/rm inside a throwaway directory, including recursive forms | 0 | PASS | `45c415f706ec` |
| `TE-44-B` | cp copies a file and mv renames the copy | 0 | PASS | `7a321726fc9b` |
| `TE-44-C` | expected non-zero exit: cp of a file that does not exist is an error and creates nothing | 1 | PASS | `bf5d10f428d6` |

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
- [Answer questions about a log file with a pipeline](https://kairos-2z6s.onrender.com/res/log-pipeline-full-en)
- [diff: see what changed between two files](https://kairos-2z6s.onrender.com/res/diff-basics-full-en)
- [find: list files by name and sort the result](https://kairos-2z6s.onrender.com/res/find-basics-full-en)
- [find: -maxdepth, -type f and -size +1c narrow the result](https://kairos-2z6s.onrender.com/res/find-options-full-en)
- [Deleting .env in a new commit does not hide the key](https://kairos-2z6s.onrender.com/res/deleted-env-still-in-history-en)
- [Bash variables, loops and if: the basics](https://kairos-2z6s.onrender.com/res/bash-variables-loops-full-en)
