Phase 1: Foundations - mishraxharshit/harshitxmishra.github.io GitHub Wiki

Previous: Home | Next: Phase 2 — Command Line


What You Will Learn in This Phase

  • What Linux is and how it differs from Windows and macOS
  • The architecture of a Linux system: kernel, shell, and user space
  • How Linux organises its files (the Filesystem Hierarchy Standard)
  • How to open a terminal and run your first commands
  • What a Linux distribution is and which one to choose

1.1 What Is Linux?

Linux is an operating system kernel. A kernel is the core software that sits between your hardware (CPU, RAM, disk, network card) and the programs you run. It manages resources: which program gets CPU time, how memory is allocated, how data flows to and from storage.

The term "Linux" is often used loosely to mean an entire operating system, but strictly speaking, Linux is just the kernel. A complete usable system is built by combining the Linux kernel with a collection of tools, libraries, and a package manager. This combination is called a distribution (or distro).

Key facts:

  • Linux was created by Linus Torvalds in 1991, initially as a hobby project
  • It is open source: anyone can read, modify, and redistribute the source code
  • It powers the vast majority of the world's servers, all Android phones, and most supercomputers
  • The same kernel runs on a Raspberry Pi, a laptop, and a 10,000-core data centre machine

1.2 The Architecture of a Linux System

Understanding the layers of a Linux system prevents enormous confusion later. Here is what the system looks like from the bottom up.

+-----------------------------------------+
|           User Applications             |
|  (browser, text editor, scripts, etc.)  |
+-----------------------------------------+
|                 Shell                   |
|  (bash, zsh — interprets your commands) |
+-----------------------------------------+
|         C Standard Library (glibc)      |
|   (translates program calls to kernel)  |
+-----------------------------------------+
|            Linux Kernel                 |
|  (process scheduling, memory, drivers)  |
+-----------------------------------------+
|             Hardware                    |
|  (CPU, RAM, Disk, Network, USB, etc.)   |
+-----------------------------------------+

The Kernel handles five core responsibilities:

  1. Process management: starting, pausing, and stopping programs
  2. Memory management: giving programs memory, reclaiming it when programs end
  3. File system management: reading and writing to storage devices
  4. Device drivers: communicating with hardware (keyboard, disk, network card)
  5. System calls: providing a secure interface for programs to request kernel services

The Shell is the program that reads your typed commands and executes them. When you type ls, the shell finds the ls program, asks the kernel to run it, and displays the output. The default shell on most systems is Bash (Bourne Again Shell).

User Space is everything that runs as a regular program, outside the kernel. Every application you interact with — a text editor, a web server, a Python script — runs in user space.


1.3 The Filesystem Hierarchy Standard

Linux organises all files in a single tree rooted at / (called the root directory). There are no drive letters like C: or D:. Everything — including external drives and network mounts — appears somewhere under /.

/
├── bin/       Essential user commands (ls, cp, mv, cat)
├── sbin/      System administration commands (fdisk, ip, systemctl)
├── etc/       Configuration files for all programs
├── home/      Personal directories for each user (/home/alice, /home/bob)
├── root/      Home directory for the root (admin) user
├── var/       Variable data: logs, databases, mail queues
├── tmp/       Temporary files, cleared on reboot
├── usr/       Installed programs and libraries
│   ├── bin/   User programs (git, python3, vim)
│   ├── lib/   Shared libraries
│   └── share/ Architecture-independent data, man pages
├── lib/       Essential shared libraries and kernel modules
├── proc/      Virtual filesystem: information about running processes
├── sys/       Virtual filesystem: information about devices and kernel
├── dev/       Device files (disks appear as /dev/sda, terminal as /dev/tty)
├── boot/      Kernel image and bootloader configuration
├── mnt/       Temporary mount point for filesystems
└── media/     Mount points for removable media (USB, DVD)

Why this matters: When you configure a program, its configuration file is in /etc/. When a program writes a log, it goes into /var/log/. When you install software, it typically ends up in /usr/bin/. Knowing this structure means you always know where to look.

Practical example:

# See the top-level directories
ls /
 
# See what is in /etc (partial output)
ls /etc | head -20
 
# Find where the 'ls' command lives
which ls
# Output: /usr/bin/ls

1.4 Opening a Terminal and Running Your First Commands

The terminal is a text interface for talking to the shell. On a desktop Linux system, you can open a terminal by pressing Ctrl+Alt+T on Ubuntu, or by searching for "Terminal" in the application menu.

When the terminal opens, you see a prompt. It typically looks like this:

alice@myserver:~$

This tells you:

  • alice — the current user's name
  • myserver — the hostname of the machine
  • ~ — the current directory (~ means your home directory)
  • $ — you are a regular user (if it shows #, you are root/admin)

Your first five commands:

# Print the current directory you are in
pwd
# Output: /home/alice
 
# List files in the current directory
ls
# Output: Desktop  Documents  Downloads  Music  Pictures
 
# List files with details (permissions, size, date)
ls -l
# Output:
# drwxr-xr-x 2 alice alice 4096 Jan 15 10:30 Desktop
# drwxr-xr-x 2 alice alice 4096 Jan 14 08:22 Documents
 
# Print a message (useful for scripts later)
echo "Hello, Linux"
# Output: Hello, Linux
 
# Show who you are logged in as
whoami
# Output: alice

1.5 Understanding a Linux Distribution

A Linux distribution packages the kernel with a set of software to create a complete operating system. Different distributions make different choices about package management, default tools, update policy, and target audience.

Distribution Base Package Manager Best For
Ubuntu Debian apt Beginners, desktops, servers
Debian apt Stability, servers
Fedora Red Hat dnf Cutting edge, desktops
CentOS Stream Red Hat dnf Enterprise servers
Arch Linux pacman Advanced users, full control
Alpine Linux apk Containers, minimal footprint
Raspberry Pi OS Debian apt Raspberry Pi boards

Which one should you use to learn? Use Ubuntu 22.04 LTS. It has the largest community, the most online help, long-term support until 2027, and its commands are representative of most production server environments.


1.6 The Boot Process

Understanding how Linux starts helps you diagnose boot failures and understand where configuration lives.

Power on
    |
    v
BIOS / UEFI firmware runs
  Performs hardware self-test (POST)
  Finds the boot device (disk, USB)
    |
    v
Bootloader (GRUB2)
  Presents a menu if multiple kernels are installed
  Loads the kernel image (/boot/vmlinuz-...) into memory
  Loads the initial RAM disk (/boot/initrd.img-...)
    |
    v
Linux Kernel initialises
  Detects hardware
  Mounts the initial RAM disk as a temporary root filesystem
  Finds and mounts the real root filesystem
    |
    v
Init system (systemd on modern distros)
  PID 1 — the first process, parent of all others
  Reads unit files from /etc/systemd/system/
  Starts services in parallel (networking, display, login)
    |
    v
Login prompt or graphical desktop

Practical check:

# See how long the last boot took and which services were slow
systemd-analyze blame | head -20
 
# See the boot log
journalctl -b 0 | head -50
# -b 0 means "current boot", -b -1 means "previous boot"

1.7 Getting Help

Linux has a built-in documentation system. Before searching online, check these sources:

# man pages: the authoritative manual for every command
man ls
# Press Space to scroll, q to quit, / to search within the page
 
# --help flag: a quick summary of options
ls --help
 
# info pages: more detailed documentation for GNU tools
info coreutils
 
# apropos: search for commands related to a keyword
apropos "list files"
# Output shows commands whose man page descriptions match the keyword
 
# type: shows what kind of command something is
type ls
# Output: ls is aliased to 'ls --color=auto'
 
type cd
# Output: cd is a shell builtin

Reading a man page: The synopsis section of a man page uses a notation you will see everywhere:

ls [OPTION]... [FILE]...
  • Square brackets [...] mean optional
  • ... means you can repeat this argument multiple times
  • Uppercase words are placeholders for actual values you provide

1.8 Virtual Terminals

Linux supports multiple virtual terminals. Even in a graphical desktop environment, you can press Ctrl+Alt+F2 through Ctrl+Alt+F6 to switch to a text-only terminal. Press Ctrl+Alt+F1 or Ctrl+Alt+F7 to return to the graphical session.

This is useful when the graphical interface is frozen: you can switch to a text terminal, log in, and diagnose or fix the problem.


Phase 1 Exercises

Complete these exercises before moving to Phase 2. They take 20 to 30 minutes.

Exercise 1: Open a terminal and run uname -a. Write down what each part of the output means.

Exercise 2: Use ls -la / to list the root directory. Identify at least five directories and explain what each one is used for.

Exercise 3: Read the man page for the pwd command. Then read it for echo. Practice pressing / to search within the man page.

Exercise 4: Run systemd-analyze. Note the total boot time. Then run systemd-analyze blame and identify the three slowest services.

Exercise 5: Use which bash to find where bash is installed. Then run ls -l /bin/bash and note the file size and date.


Common Mistakes in Phase 1

Mistake: Treating Linux like Windows Linux is case-sensitive. Documents and documents are different directories. LS is not the same command as ls.

Mistake: Typing spaces in filenames without quoting them A file named my document.txt causes problems because the shell treats the space as a separator between two arguments. Use quotes: ls "my document.txt" or underscores: my_document.txt.

Mistake: Closing the terminal instead of typing exit Always type exit or press Ctrl+D to close a shell session, especially when connected to a remote server over SSH. Closing the window without exiting may leave orphaned processes.


Previous: Home | Next: Phase 2 — Command Line