Beginner · 6 min · practise every command in the built-in terminal

Viewing Files with cat

cat — Concatenate and print

cat README.txt
cat documents/hello.txt

cat prints the entire file content to the terminal.

cat with multiple files

cat file1.txt file2.txt

Prints both files one after another.

Writing to files with cat

cat > newfile.txt

Type your content, then press Ctrl+D to save.

Appending with cat

cat >> existing.txt

Adds to the end of the file.

cat with line numbers

cat -n myfile.txt

For large files

cat prints everything at once. For big files, use:

  • less filename — scroll through pages
  • head filename — first 10 lines
  • tail filename — last 10 lines

Practice tasks

  1. View the contents of README.txt
  2. View documents/hello.txt
  3. View README.txt with line numbers shown
  4. Create a new file and type content directly into it using cat

Commands in this lesson

Files & Directories