Linux: Terminal Basics — Shell and Your First Command
The terminal is the primary way developers interact with Linux. It lacks the flashiness of a graphical interface, but its efficiency — once you get the hang of it — far surpasses clicking a mouse.
📋 Prerequisites: You should first complete
- Lesson 2: Installing Linux
1. What You Will Learn
- The difference between Shell and terminal emulators
- General command syntax (command + options + arguments)
- Tab auto-completion and command history
- Terminal keyboard shortcuts
- How to get command help
2. A Beginner's First Terminal Experience
(1) The Pain: A Black Window with White Text Is Intimidating
Alex opened the WSL2 terminal and saw only a black window with a blinking cursor. He didn't know what to type or what would happen when he pressed Enter. He didn't even know how to exit.
(2) The First Command
Senior engineer Bob said: "Say hello first. Type echo "Hello Linux" and press Enter."
echo "Hello Linux"
# Output: Hello Linux
The terminal echoed back what he typed — Alex realized the terminal is like a conversation window: you type a command, and the computer replies with the result.
(3) The Benefit: From Anxiety to Control
After learning his first command, Alex tried date, whoami, and cal. Within 5 minutes, he went from "afraid to touch the terminal" to "able to read terminal output."
3. Knowledge Points
(1) Shell and Terminal
A terminal emulator is the window you see — GNOME Terminal on Linux, Windows Terminal on Windows, Terminal.app on macOS.
The Shell is the program running inside the terminal, responsible for interpreting the commands you type. The most common Shell is bash (Bourne Again Shell).
Terminal window → Shell (bash) → Operating System
(2) General Command Syntax
Almost all Linux commands follow this structure:
COMMAND [OPTIONS] [ARGUMENTS]
| Part | Explanation | Example |
|---|---|---|
| COMMAND | The name of the command to execute | ls |
| OPTIONS | Options that modify command behavior (usually start with -) |
-l (long format), -a (show hidden) |
| ARGUMENTS | The target the command operates on | Filename, directory name |
# Syntax example
ls -la /home
# Command: ls
# Options: -l (long format) and -a (hidden files)
# Argument: /home (directory to list)
(3) Tab Auto-Completion
The Tab key is the most useful key in the terminal. You only need to type part of a command or filename, and pressing Tab will auto-complete it.
Ctrl+R reverse history search, your efficiency can increase several times.
| Tab effect | Description |
|---|---|
| Auto-complete | Automatically completes the full name when there's a unique match |
| Show all matches | When there are multiple matches, one press does nothing; two presses show all options |
| Complete command | Type ec + Tab → auto-completes to echo |
| Complete file | cd /ho + Tab → auto-completes to cd /home |
| Complete path | ls ~/Doc + Tab → ls ~/Documents/ |
(4) Terminal Keyboard Shortcuts
| Shortcut | Action |
|---|---|
Ctrl + C |
Terminate the currently running program (not copy!) |
Ctrl + D |
Exit the current Shell or end input (EOF) |
Ctrl + L |
Clear the screen (same as clear command) |
Ctrl + R |
Reverse search through command history |
↑ / ↓ |
Browse command history |
Ctrl + A |
Move cursor to the beginning of the line |
Ctrl + E |
Move cursor to the end of the line |
Ctrl + U |
Delete all characters before the cursor |
Ctrl + K |
Delete all characters after the cursor |
Ctrl + W |
Delete the word before the cursor |
Ctrl+A goes to line start (like Emacs), Ctrl+E goes to line end, Ctrl+U clears before cursor, Ctrl+K clears after cursor, Ctrl+W deletes the previous word. Memorize these combinations and editing long commands becomes much faster.
(5) ▶ Example: Basic Interactive Commands
# View current date and time
date
# Output: Tue Jul 7 10:23:45 CST 2026
# Print current username
whoami
# Output: alice
# View calendar
cal
# July 2026
# Su Mo Tu We Th Fr Sa
# 1 2 3 4
# 5 6 7 8 9 10 11
# ...
# View system uptime
uptime
# Output: 10:23 up 2 days, 2 users
Output:
TEXTTue Jul 7 10:23:45 CST 2026 alice July 2026 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 10:23 up 2 days, 2 users
(6) ▶ Example: Various Uses of the echo Command
# Print a string
echo "Hello Linux"
# Print a variable
echo "Current user is: $USER"
# Print command output
echo "Today is $(date +%A)"
# Write to a file
echo "Hello World" > welcome.txt
(7) ▶ Example: Tab Completion Practice
# Type cd /h then press Tab → auto-completes /home
cd /home
# Type ls -l /e then press Tab → auto-completes /etc
ls -l /etc
# Press Tab twice to show matches (type cd /e + Tab + Tab)
# Lists all paths starting with /e
(8) ▶ Example: Clearing the Screen and Exiting
# Too much on screen? Clear it
clear
# Or use the shortcut Ctrl + L
# Exit the terminal
exit
# Or press Ctrl + D
(9) ▶ Example: Getting Command Help
# Method 1: --help option (supported by most commands)
ls --help | head -20
# Method 2: man pages (most detailed)
man ls
# Press q to exit the man page
# Method 3: whatis one-line description
whatis ls
# Output: ls (1) - list directory contents
(10) ▶ Comprehensive Example: Alex's First Terminal Adventure
# After opening the terminal, Alex tried the following
echo "Hello Linux" # Say hello to the computer
date # What's today's date?
whoami # Who am I?
uptime # How long has the server been running?
cal # Show this month's calendar
ls -la # What files are in my home directory?
echo $SHELL # What Shell am I using?
exit # Goodbye, terminal!
Output:
TEXTHello Linux Tue Jul 8 10:23:45 CST 2026 alice 10:23:45 up 3 days, 2:10, 1 user, load average: 0.00, 0.01, 0.05 July 2026 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 total 28 drwxr-xr-x 1 alice alice 4096 Jul 8 10:23 . drwxr-xr-x 1 alice alice 4096 Jul 8 10:23 .. -rw-r--r-- 1 alice alice 220 Jul 8 10:23 .bash_logout -rw-r--r-- 1 alice alice 3771 Jul 8 10:23 .bashrc -rw-r--r-- 1 alice alice 807 Jul 8 10:23 .profile /bin/bash💡 Alex has learned the most basic terminal commands — he'll continue building on these in the following chapters!
❓ FAQ
Q: What's the difference between a terminal and a Shell? A: A terminal is the window program (e.g., GNOME Terminal, Windows Terminal), while a Shell is the command interpreter running inside the terminal (e.g., bash, zsh). The terminal provides the "window," and the Shell is "the person talking to you."
Q: What can Tab complete in the terminal? A: Command names, filenames, directory names, command options (some programs support this), and environment variable names (when starting with
$). On Linux,Ctrl + Iand Tab are the same thing.
Q: What if pressing Ctrl + C doesn't stop the program? A: First try
Ctrl + C, thenCtrl + Zto suspend the program, followed bykill %1to terminate it. If that still doesn't work, useps aux | grep program_nameto find the PID and thenkill -9 PID.
Q: What's the difference between
clearand Ctrl + L? A: Same effect — both clear the screen. Butclearis a command (clears the terminal and scroll buffer), whileCtrl + Lis a shortcut (only clears the visible portion). You can use either in practice.
Q: How do I view previously entered commands? A: Press
↑to browse one by one. PressCtrl + Rto enter reverse search mode and search history by keyword. All history is saved in~/.bash_history.
📖 Summary
- The terminal is the window; the Shell is the command interpreter; the default Shell is bash
- Command structure:
COMMAND [OPTIONS] [ARGUMENTS] - Tab auto-completion is the terminal's most powerful feature — press Tab often
- Terminal shortcuts greatly boost efficiency:
Ctrl + Cto terminate,↑for history,Ctrl + Rto search - Get help with
--help(brief) orman(detailed)
📝 Exercises
- Basic (Difficulty ⭐): Open the terminal, type
echo "Hello Linux"and observe the output, then usedateandcalto view the current date and calendar - Intermediate (Difficulty ⭐⭐): Read the
lscommand manual withman ls(press q to exit), and practice Tab completion — typecd /then press Tab twice to see what directories exist - Advanced (Difficulty ⭐⭐⭐): Create a Shell alias
todaythat displays both the date and calendar; then useCtrl + Rto search your command history and list your 5 most-used terminal shortcuts