Learn to Code
All tracks
Learn to Code

Free lessons from scratch to pro — every language, databases and DevOps.

AboutContactPrivacy PolicyTerms of Use

Your progress is saved in this browser. © 2026 Learn to Code

>_
Terminal & Command Line
0/10 completed
Beginner
What is the terminal?Navigating foldersWorking with files and foldersViewing files
Intermediate
Wildcards and finding filesPipes and redirectionText processing: grep, sort, cut and friends
Advanced
Environment variables and PATHPermissions and processes
Pro
Shell productivity: aliases, scripts and dotfiles
Tracks / Terminal & Command Line / Beginner

Viewing files

You'll often need to look inside files: config files, logs, data and code. The terminal has a tool for every situation, from tiny files to logs with millions of lines.

cat: print a whole file

Linux terminal (simulator) · editable
  • cat (short for concatenate) prints files. With several files, it joins them.
  • -n adds line numbers.
  • It's best for short files. A huge file would flood your screen.

head and tail: the start and the end

Linux terminal (simulator) · editable
Command Shows
head file The first 10 lines
head -n 3 file The first 3 lines
tail file The last 10 lines
tail -n +2 file Everything from line 2 onwards (handy for skipping a CSV header)
tail -f file Follow a file live as new lines are added, which is perfect for watching logs. Ctrl + C to stop.

tail -f /var/log/app.log is one of the most-used commands on servers: you watch errors appear in real time while you reproduce a bug.

less: scroll through big files

On a real machine, less bigfile.log opens a scrollable viewer:

Key Action
Space / b Page down / up
↑ ↓ Line by line
/word Search forward for "word" (n = next match)
G / g Jump to the end / start
q Quit

(The simulator just prints the file for less.)

wc: count lines, words and characters

Linux terminal (simulator) · editable

wc -l (count lines) is everywhere: "how many users are in this file?", "how many errors today?"

File sizes and disk usage

Linux terminal (simulator) · editable
  • ls -lh shows each file's size in human units.
  • du -sh folder shows a folder's total size.
  • df -h (on real machines) shows how full your disks are.

Editing files in the terminal

Sooner or later you'll need to edit a file on a server with no GUI:

Editor Difficulty Quick survival guide
nano Easy Edit normally. Ctrl + O saves, Ctrl + X exits. The shortcuts are shown at the bottom.
vim Steep curve, very powerful Press i to type. Press Esc, then :wq + Enter to save and quit, or :q! to quit without saving.
code VS Code code . opens the current folder in VS Code (if it's installed)

The simulator has no editors, but you can create and change files with echo:

Linux terminal (simulator) · editable

> replaces a file's contents, and >> appends to it. More in the Pipes lesson.

Practice

  1. How many lines are in data/app.log?
  2. Show only the header (first line) of data/sales.csv.
  3. Show the last 3 entries of the log.
  4. Show Documents/todo.txt with line numbers.
Linux terminal (simulator) · editable
✎ Check your understanding

1.Which command shows the last 20 lines of a log file?

2.What does tail -f app.log do?

← Working with files and folders