Skip to main content

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.

Opening the Terminal
# 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 Syntax Pattern
command [options] [arguments]

Let's explore some fundamental commands:

Essential First 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:

Interactive Command Session
# 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
tip

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:

Efficiency Features
# 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:

Using Manual Pages
# 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

Terminal Session Management

Learn to control your terminal sessions effectively:

Session Control Commands
# 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
warning

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. LS won't work, but ls will
  • 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 sudo when 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
  1. What does the pwd command display?
  2. How can you view the manual page for the ls command?
  3. What keyboard shortcut terminates a running command?
  4. Why might LS return "command not found" when ls works fine?
  5. What does the -l option do when used with the ls command?

Answers:

  1. The current working directory (Print Working Directory)
  2. Using man ls command
  3. Ctrl + C
  4. Linux commands are case-sensitive, and LS is different from ls
  5. Displays files in long format with detailed information