Create Files Without an Editor Using Cat
No text editor in your shell? #
Sometimes, you might find yourself debugging or tinkering in an environment that has only the minimal set of utilities installed.
Some container images omit everything except the few utilities actually needed for the software being run and/or minimal debugging, because they're based (rightfully so) on extremely minimal base images like distroless, scratch, etc.
Take, for example, minio images - they contain a shell, but no text editor:
$ docker run --entrypoint sh -it --rm minio/minio:RELEASE.2025-07-23T15-54-02Z
sh-5.1# $SHELL --version | head -1
GNU bash, version 5.1.8(1)-release (x86_64-redhat-linux-gnu)
sh-5.1# vi testfile
sh: vi: command not found
sh-5.1# nano testfile
sh: nano: command not found
sh-5.1# vim testfile
sh: vim: command not found
# No joe, no ed, no nothing
The "correct" way of interacting with this environment (and passing files to it) would be to pass some environment variables or volumes to the container. But let's say you really wanted to create a text file right here, right now - maybe you're in a rush, maybe you're debugging before actually doing it the correct way.
cat for.. writing files? #
Most likely, if an environment has a shell at all, it will have cat - even if it doesn't have a text editor:
sh-5.1# cat > testfile
some test content
press Ctrl+D in the next line
sh-5.1# cat testfile
some test content
Note that to write the file, you have to press Ctrl+D on a new, empty line.
It fully supports pasting in any file contents, allowing you to quickly create files in a constrained environment.
Overriding EOF #
Ctrl+D sends an "end-of-file" character, which is the default signal cat looks for to stop reading a file (in this case, it's reading stdin).
If, for some reason, you want to use a different signal, you can do it like so:
sh-5.1# cat <<- "arbitrary-string-banana" > testfile-with-arbitrary-EOF
> first line
> arbitrary-string-banana
sh-5.1# cat testfile-with-arbitrary-EOF
first line
This syntax makes cat read a "heredoc", visibly shown by the new > prefixes for each read line, which we're not going to get into here - but as you can see, cat terminated when it encountered the arbitrary string we've set.
Not for editing files (and a tiny workaround) #
cat isn't an editor - you can't jump to a line, delete in the middle, or reorder text. It's great for creating files or appending, but not for in‑place edits. Keep in mind:
cat > fileoverwrites the file.cat >> fileonly appends to the end.
Workaround: If the file is small enough, just rewrite it. Show the new, full contents and save:
sh-5.1# cat > config.yaml
# paste the entire, updated file content here
# …
# then press Ctrl+D on a new, empty line
If you want to double-check that files are written correctly, write to a temp file and then replace the original:
sh-5.1# cat > config.yaml.tmp
# paste content, Ctrl+D
sh-5.1# cat config.yaml.tmp
# inspect content
sh-5.1# mv config.yaml.tmp config.yaml