DevOps

Basic Linux

What is Linux

Linux is a free, open-source operating system kernel first released by Linus Torvalds in 1991. Today it powers everything from personal computers and servers to smartphones (Android) and cloud infrastructure.

Key characteristics:

  • Open source — source code is publicly available and freely modifiable
  • Multi-user — multiple users can use the system simultaneously
  • Multi-tasking — runs multiple processes concurrently
  • Portable — runs on many hardware architectures
  • Secure — fine-grained permission system

Popular Linux distributions include Ubuntu, Debian, CentOS/RHEL, Fedora, and Arch Linux.


Linux Architecture

Linux is structured as layered components, each building on top of the one below it. This separation keeps the kernel isolated from user-facing software.

┌─────────────────────────────────────────────────────────┐
│                      Application                        │
│         browsers · editors · scripts · compilers        │
│                                                         │
│   ┌─────────────────────────────────────────────────┐   │
│   │                     Shell                       │   │
│   │              bash · zsh · sh · fish             │   │
│   │                                                 │   │
│   │   ┌─────────────────────────────────────────┐   │   │
│   │   │                 Kernel                  │   │   │
│   │   │     memory · CPU · I/O · drivers        │   │   │
│   │   │                                         │   │   │
│   │   │   ┌─────────────────────────────────┐   │   │   │
│   │   │   │            Hardware             │   │   │   │
│   │   │   │    CPU · RAM · Disk · NIC       │   │   │   │
│   │   │   └─────────────────────────────────┘   │   │   │
│   │   └─────────────────────────────────────────┘   │   │
│   └─────────────────────────────────────────────────┘   │
└─────────────────────────────────────────────────────────┘
LayerRole
ApplicationPrograms users run directly — everything you interact with
ShellTranslates commands into kernel system calls (bash, zsh)
KernelCore OS — manages memory, scheduling, I/O and device drivers
HardwarePhysical CPU, RAM, disks, and network interfaces

Linux Boot Process

When you press the power button, Linux goes through a fixed sequence before handing control to you.

  ┌──────────┐     ┌────────────┐     ┌──────────┐     ┌──────────┐
  │ Power On │────►│ BIOS/UEFI  │────►│  MBR/GPT │────►│   GRUB   │
  │          │     │ POST check │     │ find boot│     │ OS menu  │
  └──────────┘     └────────────┘     └──────────┘     └────┬─────┘


  ┌──────────┐     ┌────────────┐     ┌──────────┐     ┌──────────┐
  │  Login   │◄────│  systemd   │◄────│initramfs │◄────│  Kernel  │
  │  prompt  │     │  PID = 1   │     │ temp fs  │     │ into RAM │
  └──────────┘     └────────────┘     └──────────┘     └──────────┘

Boot stages explained

StageWhat happens
BIOS / UEFIFirmware runs POST (Power-On Self Test) to verify hardware
MBR / GPTFirst 512 bytes of disk; points to the bootloader location
GRUBBootloader presents a menu and loads the selected kernel image
KernelDecompresses itself, initialises hardware drivers and mounts initramfs
initramfsMinimal temporary filesystem used to mount the real root (/)
systemdPID 1 — starts all system services in parallel based on target units
Logingetty presents the login prompt (or display manager for GUI)

Why does /boot matter? The kernel image (vmlinuz), initial ramdisk (initrd/initramfs), and GRUB config all live in /boot. If this partition fills up, the system cannot update or boot a new kernel.


Linux Directory Structure

Linux uses a hierarchical file system rooted at / (the root directory). Every file and directory lives under this single tree.

DirectoryPurpose
/Root — top of the filesystem hierarchy
/binEssential user binaries (ls, cp, mv)
/sbinSystem binaries for root (fdisk, ifconfig)
/etcSystem configuration files
/homeUser home directories (/home/alice)
/rootHome directory for the root user
/varVariable data — logs, databases, mail spools
/tmpTemporary files (cleared on reboot)
/usrUser programs and libraries
/libShared libraries for /bin and /sbin
/devDevice files (disks, terminals)
/procVirtual filesystem for process/kernel info
/sysVirtual filesystem for hardware info
/optOptional/third-party software
/mntMount points for temporary filesystems
/mediaMount points for removable media
/bootKernel and bootloader files

Tip: Everything in Linux is a file — even hardware devices are represented as files under /dev.


Basic Navigation

Navigate the filesystem confidently with these essential commands.

pwd
# /home/alice

List Directory Contents

ls              # simple listing
ls -l           # long format (permissions, size, date)
ls -la          # include hidden files (start with .)
ls -lh          # human-readable file sizes
ls -lt          # sort by modification time
ls /etc         # list a specific directory

Change Directory

cd /etc             # absolute path
cd Documents        # relative path
cd ..               # go up one level
cd ~                # go to home directory
cd -                # go to previous directory

Understanding Paths

  • Absolute path — starts from root: /home/alice/docs/report.txt
  • Relative path — relative to current directory: docs/report.txt
  • . — current directory
  • .. — parent directory
  • ~ — home directory

File Operations

Creating Files and Directories

touch filename.txt          # create empty file (or update timestamp)
mkdir my-directory          # create directory
mkdir -p a/b/c              # create nested directories

Copying Files

cp source.txt dest.txt          # copy file
cp -r source-dir/ dest-dir/     # copy directory recursively
cp -p source.txt dest.txt       # preserve timestamps and permissions

Moving and Renaming

mv old-name.txt new-name.txt    # rename file
mv file.txt /tmp/               # move file to /tmp
mv dir1/ /opt/dir2              # move and rename directory

Removing Files

rm file.txt             # remove file
rm -i file.txt          # interactive (prompt before removing)
rm -r directory/        # remove directory and contents
rm -rf directory/       # force remove (no prompts) — USE WITH CAUTION

Viewing File Contents

cat file.txt            # print entire file
less file.txt           # page through file (q to quit)
head -n 20 file.txt     # show first 20 lines
tail -n 20 file.txt     # show last 20 lines
tail -f /var/log/syslog # follow a file in real time

Finding Files

find /home -name "*.txt"            # find by name
find / -type f -size +100M          # find files larger than 100MB
find /etc -mtime -7                 # modified in last 7 days
locate filename                     # fast search using index (requires updatedb)
which python3                       # find location of a command
whereis bash                        # find binary, source, and man pages