Skip to main content

Command Line Basics

The command line interface (CLI) is your gateway to powerful system control. Master these fundamentals to efficiently navigate and manage Linux systems.

Getting Started with the Terminal

What is the Command Line?

The command line is a text-based interface where you type commands to interact with your computer. Unlike graphical interfaces, the CLI provides direct, precise control over your system.

Opening the Terminal

  • Ubuntu/Debian: Ctrl + Alt + T
  • macOS: Cmd + Space, type "Terminal"
  • Windows: Use WSL (Windows Subsystem for Linux)

Essential Commands

# Show current directory
pwd

# List files and directories
ls
ls -la # Detailed listing with hidden files

# Change directory
cd /path/to/directory
cd ~ # Go to home directory
cd .. # Go up one level
cd - # Go to previous directory

File Operations

# Create files
touch filename.txt
echo "Hello World" > file.txt

# View file contents
cat filename.txt
less filename.txt # Paginated view
head filename.txt # First 10 lines
tail filename.txt # Last 10 lines

# Copy, move, and delete
cp source.txt destination.txt
mv oldname.txt newname.txt
rm filename.txt
rm -rf directory/ # Remove directory and contents

Directory Operations

# Create directories
mkdir new_directory
mkdir -p path/to/nested/directory

# Remove directories
rmdir empty_directory
rm -rf directory_with_contents

Command Structure

Every Linux command follows this pattern:

command [options] [arguments]

Examples:

  • ls -l /home - List detailed info for /home directory
  • cp -r source/ dest/ - Copy directory recursively
  • grep -i "error" logfile.txt - Search for "error" (case-insensitive)

Getting Help

# Manual pages
man command_name
man ls

# Quick help
command_name --help
ls --help

# Command information
which command_name
type command_name

Practice Exercises

  1. Navigation Practice:

    • Navigate to your home directory
    • Create a directory called "aws-practice"
    • Navigate into it and create subdirectories: "scripts", "configs", "logs"
  2. File Management:

    • Create a file called "server-info.txt"
    • Add some text content to it
    • Copy it to each subdirectory
    • List all files recursively
  3. Exploration:

    • Explore the /etc directory
    • Find configuration files
    • Use grep to search for specific content

Next Steps

Once you're comfortable with basic navigation and file operations, you'll be ready to explore the Linux File System structure and organization.

AWS Connection

These command line skills directly apply to:

  • Managing EC2 instances via SSH
  • Configuring AWS CLI
  • Automating tasks with shell scripts
  • Troubleshooting cloud infrastructure

Lesson Quiz

Test your command-line fundamentals. You can start, skip, or proceed to the next lesson.

Lesson Summary

Key command-line concepts to remember. Use Save as PDF to export these flash cards.

pwd

navigation
Prints current working directory path.

ls -la

listing
Lists files with details including hidden files.

mkdir -p

directories
Creates intermediate directories as needed.

grep -i

search
Case-insensitive search within files.