Moving around is great, but you came here to get things done. Let's make some files. Unix gives you a handful of ways to create files from the terminal, from the dead-simple touch to writing content directly with echo and cat.
Creating empty files โ touch
touch creates an empty file. It's also used to update a file's timestamp, but for our purposes, it's the fastest way to bring a file into existence.
$ touch notes.txt
$ ls -l
-rw-r--r-- 1 you you 0 Jun 15 11:30 notes.txt
Zero bytes. The file exists but has nothing in it yet. This is useful for creating placeholder files, log files, or markers that a script can check for.
Try it Yourself โWriting text โ echo
echo prints text to the terminal. But with the > redirect operator, you can send that text into a file instead.
$ echo "Hello, Unix!" > hello.txt
$ cat hello.txt
Hello, Unix!
The > operator creates the file (or overwrites it if it already exists). If you want to add text to the end of an existing file, use >> instead.
$ echo "Line two" >> hello.txt
$ cat hello.txt
Hello, Unix!
Line two
Writing multiple lines โ cat
You can type content directly into a file using cat with a redirect. It reads from the keyboard until you press Ctrl+D to finish.
$ cat > todo.txt
Buy groceries
Finish project
Call mom
After typing Ctrl+D (the end-of-file signal), the file is saved. cat by itself reads a file and prints it. With >, it captures what you type instead.
Which method should you use?
touchโ when you just need an empty file as a placeholderechoโ when you have one line or want to appendcatโ when you're writing a few lines and don't want to open an editor
For real editing, you'll want nano or vim, but these three commands cover quick file creation without leaving the terminal.