Making and reading files

Create folders, write a file, read it back, and learn the one command you should respect.

Now let's build things. These commands create and inspect files without leaving the keyboard.

  • mkdir name: make a new folder.
  • touch file.txt: make an empty file.
  • echo "hello" > file.txt: write text into a file (this replaces what was there).
  • cat file.txt: show what's inside a file.
  • rm file.txt: delete a file.

Careful: rm does not use a trash can. Deleted means gone. Read the command twice before you press Enter, and be extra careful with rm -rf, which deletes whole folders without asking.

Quick check

Which command shows you what is inside notes.txt?

  1. ls notes.txt
  2. cat notes.txt
  3. cd notes.txt
  4. touch notes.txt

Answer: cat notes.txt. cat prints a file's contents. ls lists names, cd enters folders, and touch creates (or just updates) a file.