DevOps

Linux Basics

Master Linux fundamentals including architecture, file system structure, and essential commands every DevOps engineer must know.

By TechCoder TeamLast updated: 2026-06-02
In a Nutshell

Master Linux fundamentals including architecture, file system structure, and essential commands every DevOps engineer must know. This hands-on tutorial focuses on practical implementation of linux basics concepts.

Linux Basics

Linux is the foundation of modern DevOps. Most servers, containers, and cloud infrastructure run on Linux. As a DevOps engineer, you need to be comfortable navigating and managing Linux systems.

Linux Architecture

Linux follows a modular architecture with these key components:

┌─────────────────────────────────────┐
│         User Applications            │
│   (Shell, Editors, Browsers, etc.)   │
├─────────────────────────────────────┤
│         System Libraries             │
│   (glibc, system calls interface)    │
├─────────────────────────────────────┤
│         Linux Kernel                 │
│  (Process, Memory, Device, File     │
│   System, Network Management)        │
├─────────────────────────────────────┤
│         Hardware Layer               │
│    (CPU, Memory, Devices, I/O)       │
└─────────────────────────────────────┘

Key Components

  1. Kernel: The core that manages system resources
  2. Shell: Command-line interpreter (bash, zsh, fish)
  3. File System: Hierarchical structure for organizing files
  4. System Libraries: Functions for application development

Linux File System Hierarchy

/                    # Root directory
├── bin              # Essential user binaries
├── boot             # Boot loader files
├── dev              # Device files
├── etc              # Configuration files
├── home             # User home directories
│   └── username
├── lib              # Shared libraries
├── media            # Removable media
├── mnt              # Temporary mount points
├── opt              # Optional software
├── proc             # Process information
├── root             # Root user home
├── run              # Runtime variable data
├── sbin             # System binaries
├── srv              # Service data
├── sys              # System information
├── tmp              # Temporary files
├── usr              # User programs
│   ├── bin          # User binaries
│   ├── lib          # Libraries
│   └── local        # Local software
└── var              # Variable data
    ├── log          # Log files
    └── spool        # Spool files

Important Directories

DirectoryPurpose
/etcSystem-wide configuration files
/var/logApplication and system logs
/homeUser home directories
/tmpTemporary files (cleared on reboot)
/usr/binMost user commands
/optThird-party software

Essential Linux Commands

# Print working directory
pwd

# List directory contents
ls
ls -la        # List all files (including hidden) with details
ls -lh        # Human-readable file sizes

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

File Operations

# Create empty file
touch file.txt

# Copy files
cp source.txt dest.txt
cp -r dir1 dir2    # Copy directory recursively

# Move/Rename files
mv oldname.txt newname.txt
mv file.txt /new/location/

# Remove files
rm file.txt
rm -i file.txt     # Prompt before removing
rm -r directory    # Remove directory recursively
rm -rf directory   # Force remove (DANGEROUS!)

# View file content
cat file.txt       # Display entire file
head file.txt      # First 10 lines
tail file.txt      # Last 10 lines
tail -f file.txt   # Follow file changes (real-time)
less file.txt      # Paginated view

Directory Operations

# Create directory
mkdir newdir
mkdir -p parent/child/nested    # Create nested directories

# Remove empty directory
rmdir emptydir

# View current directory tree
tree              # Show directory structure
find . -type f    # Find all files in current directory

File Permissions

# View permissions
ls -la file.txt
# Output: -rw-r--r-- 1 user group 1234 Jan 1 12:00 file.txt
#         [permissions][owner][group]

# Change permissions
chmod 755 script.sh     # rwxr-xr-x
chmod u+x file.txt      # Add execute for user
chmod g-w file.txt      # Remove write for group
chmod o=r file.txt      # Set read-only for others

# Change ownership
sudo chown user:group file.txt
sudo chown -R user:group directory/

Process Management

# List running processes
ps aux
ps aux | grep nginx    # Filter processes

# Interactive process viewer
top
htop                   # Enhanced version (if installed)

# Kill processes
kill PID
kill -9 PID            # Force kill
killall processname    # Kill by name

# Background processes
command &              # Run in background
Ctrl + Z               # Suspend current process
bg                     # Resume in background
fg                     # Bring to foreground
jobs                   # List background jobs

System Information

# Disk usage
df -h                  # Disk space (human-readable)
du -sh directory/      # Directory size

# Memory usage
free -h

# CPU info
cat /proc/cpuinfo
lscpu

# System info
uname -a               # Kernel info
cat /etc/os-release    # OS version
uptime                 # System uptime

Networking Commands

# Network configuration
ip addr               # Show IP addresses
ip route              # Show routing table

# Test connectivity
ping google.com
curl -I https://api.example.com

# Network connections
netstat -tuln         # Show listening ports
ss -tuln              # Modern alternative to netstat
lsof -i :80           # Check what's using port 80

# DNS lookup
nslookup google.com
dig google.com

Text Processing

# Search in files
grep "pattern" file.txt
grep -i "pattern" file.txt      # Case-insensitive
grep -r "pattern" directory/    # Recursive
grep -n "pattern" file.txt      # Show line numbers

# Stream editor
sed 's/old/new/g' file.txt      # Replace text
sed -i 's/old/new/g' file.txt   # Replace in-place

# Pattern scanning
awk '{print $1}' file.txt       # Print first column
awk -F: '{print $1}' /etc/passwd # Use : as delimiter

# Sort and unique
sort file.txt
sort file.txt | uniq
sort file.txt | uniq -c         # Count occurrences

Package Management

Ubuntu/Debian (apt)

sudo apt update              # Update package list
sudo apt upgrade             # Upgrade installed packages
sudo apt install nginx       # Install package
sudo apt remove nginx        # Remove package
sudo apt search nginx        # Search for package
apt list --installed         # List installed packages

RHEL/CentOS (yum/dnf)

sudo yum update              # Update packages
sudo yum install nginx       # Install package
sudo yum remove nginx        # Remove package
sudo yum search nginx        # Search for package

# Using dnf (newer)
sudo dnf install nginx

Users and Permissions

User Management

# Add user
sudo adduser username
sudo useradd -m username     # Create with home directory

# Set password
sudo passwd username

# Add to group
sudo usermod -aG sudo username   # Add to sudo group

# Switch user
su - username               # Switch to user with environment
sudo -i                     # Switch to root

# View current user
whoami
id                          # Show user and group IDs

Understanding Permissions

-rw-r--r-- 1 owner group 1234 Jan 1 12:00 file.txt

[1]    [2]   [3]   [4]
 │       │     │     │
 │       │     │     └── Group
 │       │     └──────── Owner
 │       └────────────── Permissions
 └────────────────────── File type (- file, d directory, l link)

Permissions: rwx rwx rwx
            │││ │││ │││
            │││ │││ │└─ Others execute
            │││ │││ └── Others write
            │││ ││└─── Others read
            │││ │└──── Group execute
            │││ └───── Group write
            ││└─────── Group read
            │└──────── User execute
            └───────── User write
                      User read

Quiz

Quiz

Question 1 of 5

Which directory contains system-wide configuration files in Linux?

/home
/etc
/usr
/tmp

Next Steps

Now let's explore advanced Linux concepts including shell scripting, process management, and networking fundamentals.