Introduction to Linux and the Command Line

Introduction to Linux and the Command Line

What is Linux?

Linux is an open source operating system created by Linus Torvalds in 1991. Today it is ubiquitous: web servers, smartphones (Android), IoT devices, supercomputers and of course the cloud.

Why Learn Linux?

  • Server dominance: over 90% of web servers run Linux
  • DevOps & Cloud: AWS, GCP, Azure — virtual machines are predominantly Linux
  • Open source: free, customizable, transparent
  • Stability and performance: ideal for production environments

Main Distributions

Distribution Typical Use Package Manager
Ubuntu / Debian Servers, workstations apt
CentOS / Rocky Linux Enterprise, servers dnf / yum
Alpine Docker containers apk
Arch Linux Advanced users pacman

The Terminal: Your Main Tool

The terminal (or shell) is the command line interface that allows you to interact with the system. The default shell on most distributions is Bash (Bourne Again Shell).

Getting Started

# Who am I?
whoami

# Where am I?
pwd

# What is the date?
date

# Display the machine name
hostname

# View system information
uname -a

Navigating the File System

# List files
ls
ls -la          # Detailed list with hidden files
ls -lh          # Human-readable sizes (KB, MB, GB)

# Change directory
cd /home/user
cd ..           # Go up one level
cd ~            # Go to the home directory
cd -            # Return to the previous directory

# Create directories
mkdir mon-projet
mkdir -p projets/web/frontend   # Create the entire tree

# Create files
touch fichier.txt

The Linux Directory Structure

Unlike Windows, Linux has a single directory tree starting from / (the root):

/
├── bin/        # Essential commands (ls, cp, mv...)
├── etc/        # Configuration files
├── home/       # User home directories
├── var/        # Variable data (logs, databases)
├── tmp/        # Temporary files
├── usr/        # User programs and libraries
├── opt/        # Third-party software
├── dev/        # Device files
├── proc/       # Process information (virtual)
└── root/       # Administrator's home directory

Manipulating Files

# Copy
cp fichier.txt copie.txt
cp -r dossier/ backup/        # Copy a directory recursively

# Move / Rename
mv fichier.txt nouveau-nom.txt
mv fichier.txt /tmp/           # Move

# Delete
rm fichier.txt
rm -r dossier/                 # Delete a directory
rm -rf dossier/                # Force deletion (⚠️ dangerous)

# Display file contents
cat fichier.txt
less fichier.txt               # Page-by-page navigation
head -n 20 fichier.txt         # First 20 lines
tail -n 20 fichier.txt         # Last 20 lines
tail -f /var/log/syslog        # Follow a file in real time

Searching for Files and Content

# Find files
find /home -name "*.txt"
find . -type d -name "node_modules"
find /var/log -mtime -1        # Files modified in the last 24 hours

# Search for text in files
grep "erreur" /var/log/syslog
grep -r "TODO" ./src/          # Recursive search
grep -i "warning" fichier.log  # Case-insensitive
grep -n "function" script.js   # Display line numbers

Redirections and Pipes

A fundamental Linux concept: everything is a data stream.

# Output redirection
echo "Hello" > fichier.txt      # Overwrite content
echo "World" >> fichier.txt     # Append to the end

# Error redirection
commande 2> erreurs.log         # Redirect errors
commande > sortie.log 2>&1      # Everything into one file

# Pipes: chaining commands
cat access.log | grep "404" | wc -l           # Count 404 errors
ps aux | grep nginx                            # Find nginx processes
ls -la | sort -k5 -n -r | head -10            # Top 10 largest files

Built-in Help

# Command manual
man ls
man grep

# Quick help
ls --help
grep --help

# Search for a command by description
apropos "copy files"

Best Practices

  1. Use tab for command and path autocompletion
  2. Use history with the up/down arrows or history
  3. Read error messages — they are often self-explanatory
  4. Never use rm -rf / — this deletes the entire system
  5. Prefer less over cat for long files
  6. Use man before searching on the internet