Command Line Fundamentals
Now that you have Ubuntu installed and running, it's time to dive into the heart of Linux system interaction: the command line interface (CLI). While modern Linux distributions offer graphical interfaces, the command line remains the most powerful and efficient way to control your system.
Learning Goals
By the end of this lesson, you will be able to:
- Understand what a shell is and how to access it
- Navigate and execute basic commands effectively
- Use command history and tab completion
- Understand Linux command syntax and get help
- Manage terminal sessions and processes
What is the Shell?
The shell is a command-line interpreter that provides a text-based interface to interact with the operating system. When you open a terminal application, you're launching a shell program (typically Bash in Ubuntu) that reads your commands and executes them.
# In Ubuntu Desktop, you can open the terminal using:
# Ctrl + Alt + T shortcut
# Or search for "Terminal" in the applications menu
# Once open, you'll see a prompt like:
username@hostname:~$
The prompt shows your username, hostname, and current directory (~ represents your home directory).
Basic Command Structure
Linux commands follow a consistent pattern:
command [options] [arguments]
Let's explore some fundamental commands:
# Display current date and time
date
# Show calendar
cal
# Display who is logged in
who
# Print working directory (where you are now)
pwd
# List directory contents
ls
Your First Interactive Session
Let's practice with a complete workflow:
# Check where you are
pwd
# See what files are here
ls
# Create a new directory for practice
mkdir linux-practice
# Move into that directory
cd linux-practice
# Create a test file
touch first-file.txt
# List contents to verify
ls -l
The -l option with ls gives you a "long listing" with detailed information about each file, including permissions, ownership, size, and modification date.
Command History and Completion
The shell provides powerful features to make your work more efficient:
# Press the UP arrow to cycle through previous commands
# ↑ (up arrow)
# Use Tab completion for commands and filenames
# Type "cd D" then press Tab to complete "Downloads"
# Search command history
Ctrl + R
# Then type part of a previous command to search
Getting Help
Linux provides extensive built-in documentation:
- Manual Pages
- Built-in Help
# View manual for any command
man ls
# Search manual pages by keyword
man -k "copy file"
# Navigate man pages:
# Spacebar - next page
# b - previous page
# q - quit
# For shell built-in commands
help cd
# Many commands have a --help option
ls --help
# Short help flag (common alternative)
ls -h
Terminal Session Management
Learn to control your terminal sessions effectively:
# Clear the terminal screen
clear
# Or use Ctrl + L shortcut
# Suspend a running process
Ctrl + Z
# Terminate current command
Ctrl + C
# Close terminal or exit shell
exit
Be careful with Ctrl + C - it forcefully terminates the current command. Some programs may not save data properly if interrupted this way.
Common Pitfalls
- Case sensitivity: Linux commands and filenames are case-sensitive.
LSwon't work, butlswill - Spaces in filenames: Avoid spaces or use quotes:
touch "my file.txt"or escape with backslash:touch my\ file.txt - Forgetting sudo: Some commands require administrator privileges - use
sudowhen needed - Relative vs absolute paths: Understand the difference between
./script.sh(relative) and/home/user/script.sh(absolute) - Command not found: This usually means the command isn't installed or there's a typo in the command name
Summary
You've taken your first steps into the powerful world of the Linux command line. You can now:
- Open and use the terminal effectively
- Execute basic commands with proper syntax
- Use productivity features like history and tab completion
- Access help documentation when needed
- Manage your terminal sessions
The command line may seem intimidating at first, but with practice, you'll find it's the fastest way to accomplish many tasks.
Quiz
Show quiz
- What does the
pwdcommand display? - How can you view the manual page for the
lscommand? - What keyboard shortcut terminates a running command?
- Why might
LSreturn "command not found" whenlsworks fine? - What does the
-loption do when used with thelscommand?
Answers:
- The current working directory (Print Working Directory)
- Using
man lscommand - Ctrl + C
- Linux commands are case-sensitive, and
LSis different fromls - Displays files in long format with detailed information