Linux Notes
Linux Notes
Despite the project's cancellation, two Bell Labs researchers—Ken Thompson and Dennis Ritchie—believed in the
concept of a time-sharing, multi-tasking operating system. They began working on a new, simpler OS as a side
project. Using a PDP-7 minicomputer, they created the first version of UNICS (later stylized as UNIX)—a play on the
name Multics, suggesting a more "uniplexed" system.
The real breakthrough came when Ritchie, also a pioneer in programming language design, created the C
programming language, and UNIX was rewritten in C in the early 1970s. This was revolutionary: it made UNIX
more portable and easier to modify, helping it spread across academic and research institutions.
By the mid-1970s, UNIX Version 6 had become widely used in universities, and it soon evolved into several different
proprietary and academic variants. Some of the most notable "flavors" of UNIX that emerged include:
● Sun Microsystems Solaris – Known for its robustness in enterprise and network environments.
● HP-UX – Hewlett-Packard's UNIX offering, used mostly in business and server systems.
● macOS – Although now quite distinct, Apple’s macOS has UNIX roots through BSD (Berkeley Software
Distribution), making it UNIX-compliant today.
UNIX's modularity, stability, and open philosophy (especially through early access to its source code) made it a
foundational influence on future operating systems, including Linux.
The Birth of Linux: Linus Torvalds and the Open Source Revolution
Fast forward to the early 1990s: UNIX had become well-established but was fragmented across commercial versions,
many of which were costly. At this time, Linus Torvalds, a computer science student at the University of Helsinki in
Finland, wanted to explore and experiment with UNIX-like systems. He started using MINIX, a lightweight UNIX-like
system developed by Andrew Tanenbaum for educational purposes. However, MINIX had limitations—it was not truly
free, and its development was tightly controlled.
Driven by curiosity and frustration, Linus decided to create his own operating system kernel. On August 25, 1991, he
famously announced his project in a newsgroup post and released the first version of the Linux kernel—a monolithic
kernel written in C. Just a few weeks later, on September 17, 1991, the first public version (0.01) was released.
What made Linux different was that Linus released it under the GNU General Public License (GPL), which meant
that anyone could view, use, modify, and share the source code freely. This opened the door to global collaboration,
and developers worldwide began contributing.
When Linux (the kernel) was combined with the existing GNU software stack, the result was a complete, free, and
open-source operating system often referred to as GNU/Linux. This marked a turning point in software development
and the open-source movement, emphasizing user freedom, collaboration, and transparency.
What is Linux?
Linux, in technical terms, refers specifically to the kernel—the core component of the operating system that interacts
directly with the hardware, manages system resources, and enables software applications to run. However, in
common usage, “Linux” often refers to entire Linux distributions (distros), which are complete operating systems
built around the Linux kernel and bundled with a wide range of tools and software.
Popular Linux distributions include Debian, Fedora, Arch Linux, Red Hat Enterprise Linux (RHEL), and of course,
Ubuntu.
Introduction to Ubuntu
Ubuntu is one of the most widely used and beginner-friendly Linux distributions. It was first released in October
2004 by a UK-based company called Canonical Ltd., founded by entrepreneur Mark Shuttleworth. Ubuntu is based
on Debian, another major Linux distribution known for its stability and vast package repository.
● Ease of use – Ubuntu offered a modern, graphical desktop environment (initially GNOME, later Unity, then
back to GNOME), making Linux more accessible to the average user.
● Regular release cycles – A new version of Ubuntu is released every six months, with Long-Term Support
(LTS) versions released every two years and supported for five years or more.
● Community and support – Ubuntu has a vast global community, with extensive documentation and forums
for troubleshooting and learning.
● Pre-installed software – Ubuntu comes with essential applications like Firefox, LibreOffice, and multimedia
tools, making it usable out of the box.
● Enterprise readiness – Canonical offers professional support and cloud-based tools, making Ubuntu popular
in server and cloud environments, especially with platforms like AWS and Microsoft Azure.
A Linux distribution—often called a distro—is a complete, ready-to-use operating system built around the Linux
kernel. While the kernel is the core of the operating system responsible for managing hardware and system
resources, it alone is not sufficient for daily use. A Linux distribution packages the kernel with a variety of additional
software to create a fully functional system.
● Desktop environments (e.g., GNOME, KDE, XFCE for graphical user interfaces)
Instead of requiring users to build a working OS environment from the ground up, distributions offer a pre-configured
and tested collection of tools that cater to specific use cases—such as general desktop use, programming, server
management, multimedia production, cybersecurity, or enterprise IT.
Each Linux distro has its own philosophy, target audience, and design goals, ranging from user-friendly systems
like Ubuntu to advanced, highly customizable distributions like Arch Linux.
● Copyleft requirement: If you modify and distribute GPL-licensed software, your modified version must also
be licensed under the GPL, keeping it open and accessible to others
● Package managers:
○ APT (Advanced Package Tool) – Handles installation, upgrades, and dependency management.
○ dpkg – A low-level tool used internally by APT for installing .deb packages.
● Used by: Red Hat Enterprise Linux (RHEL), Fedora, CentOS, AlmaLinux, and openSUSE.
● Package managers:
○ DNF (Dandified YUM) – Modern tool used by Fedora and newer Red Hat systems.
○ YUM – Older tool still used in some systems for backward compatibility.
1. Ubuntu
2. Debian
3. Linux Mint
6. Kali Linux
Ubuntu, one of the most widely used Linux distributions, is available in different editions tailored to meet specific
needs. The two most common editions are Ubuntu Desktop and Ubuntu Server. While they share the same core
system and are based on the same Linux kernel, they are optimized for very different use cases.
Ubuntu Desktop
Ubuntu Desktop is designed primarily for personal computing. It targets general users, students, and developers
who work on laptops and desktop computers. It provides a Graphical User Interface (GUI) and comes bundled with
a set of pre-installed applications that make it ready for use out of the box.
● Graphical Interface (GUI): Ubuntu Desktop ships with the GNOME desktop environment (as of recent
versions), providing a user-friendly and modern visual experience.
● Pre-installed Applications:
○ Firefox – Web browser
○ LibreOffice – Office suite (word processing, spreadsheets, presentations)
○ Rhythmbox, Totem, etc. – For media playback
○ Ubuntu Software Center – For installing additional software easily
● Plug-and-Play Support:
○ Recognizes and configures peripherals like printers, USB drives, Bluetooth devices, webcams,
and external monitors automatically.
● Multi-language and Accessibility Options: Great for users around the globe with diverse needs.
1. Live Version:
○ Boots directly from a USB or DVD without modifying your hard drive.
○ Useful for testing Ubuntu before installing.
○ Also used for recovery and troubleshooting.
2. Install Version:
○ A full installation setup that installs Ubuntu onto your system's hard drive.
○ Offers customization options during setup (disk partitioning, language, etc.).
Ubuntu Server
Ubuntu Server is a version of Ubuntu specially designed for deployment in data centers, enterprise environments,
and cloud platforms. Unlike the desktop version, it does not include a graphical interface by default, relying
instead on the Command-Line Interface (CLI) to conserve resources and improve performance.
● ⚙️Command-Line Based:
○ Optimized for speed, efficiency, and headless operation (no GUI).
○ Suitable for remote access and scripting.
3. Cloud Images:
○ Pre-configured, lightweight Ubuntu Server instances optimized for cloud environments.
○ Available on public clouds such as:
■ Amazon Web Services (AWS)
■ Google Cloud Platform (GCP)
■ Microsoft Azure
○ Features:
■ Fast boot times
■ Auto-scaling
■ Cloud-init support for automation
Linux Architecture
Linux Architecture
The architecture of Linux refers to the structured design and interaction between different
components of the operating system. Like most modern OSes, Linux follows a layered
architecture where each layer communicates with the one below or above it. This modular design
contributes to Linux’s portability, stability, scalability, and security.
1. Hardware
2. Kernel
3. Shell
4. Applications
Each layer plays a unique role in ensuring the smooth operation of the system.
1. Hardware Layer
This is the physical foundation of any computing system. It includes all physical components that
perform computation, input/output (I/O) tasks, storage, and networking.
Key Hardware Components:
● Input/Output Devices:
○ Includes keyboards, mice, touchpads, monitors, printers, USB drives, etc.
○ Linux uses device drivers to communicate with hardware, allowing the kernel to
abstract hardware operations from the application level.
○ Linux supports a wide range of I/O devices, thanks to its extensive and modular
driver ecosystem.
2. Kernel Layer
The kernel is the core component of Linux. It directly interacts with the hardware and manages
system resources such as CPU time, memory, disk access, and device input/output.
Main Responsibilities of the Linux Kernel:
● Process Management:
○ Manages the creation, scheduling, and termination of processes.
○ Ensures multitasking and fair CPU time distribution.
● Memory Management:
○ Allocates and deallocates memory to processes.
○ Uses virtual memory and paging to optimize performance.
● Device Management:
○ Interacts with all hardware through device drivers.
○ Offers plug-and-play support via the udev subsystem.
● Network Management:
○ Handles communication between systems using protocols like TCP/IP.
○ Supports IPv4, IPv6, firewalling, VPN, and more.
3. Shell Layer
The shell serves as a bridge between the user and the kernel. It interprets user commands and
translates them into system-level actions.
Types of Shells in Linux:
● Command-Line Shells:
○ Popular shells include Bash, Zsh, Ksh, and Fish.
○ Allows scripting and automation of tasks.
● Graphical Shells:
○ Part of the desktop environment (e.g., GNOME Shell).
○ Provide visual user interfaces for interacting with the OS.
Shell Functions:
This is the topmost layer where users interact with the operating system through applications
and software tools.
Examples of Linux Applications:
These applications run in user space, meaning they are isolated from the kernel and cannot
directly access hardware or system memory without passing through system calls.
1. Bootloader
● A program responsible for starting the Linux OS after the system is powered on.
● Loads the Linux kernel into memory and hands over control.
● Common Linux bootloaders:
○ GRUB (GRand Unified Bootloader) – most commonly used
○ LILO (Linux Loader) – older bootloader, less common today
○ BURG – a graphical bootloader built on GRUB
2. Init System:
3. Server Components:
4. Desktop Environment:
● Provides a graphical interface for users who prefer GUI over CLI.
● A desktop environment includes:
○ Window Manager (e.g., Mutter, KWin)
○ File Manager (e.g., Nautilus, Dolphin)
○ System Settings
○ Dock or Panel
● Popular Linux desktop environments:
○ GNOME – Default for Ubuntu, clean and modern
○ KDE Plasma – Highly customizable and feature-rich
○ Cinnamon – Designed for Windows users (used in Linux Mint)
○ MATE and XFCE – Lightweight, great for older machines
Shell
Shell
In a Linux-based operating system, the shell plays a critical role as the interface between the user and the
operating system kernel. It accepts commands from the user, interprets them, and communicates with the kernel to
execute the desired operations.
Think of the shell as a command interpreter—a middle layer that converts human-readable instructions into
machine-level tasks handled by the system. When a user launches a terminal window or logs into a system via SSH,
they are typically greeted by a command-line shell.
Bourne Shell One of the earliest UNIX shells, Lightweight and widely compatible;
(sh) developed by Stephen Bourne at basis for scripting standards
Bell Labs.
Bourne Again Default shell in most Linux distros, Command history, auto-completion,
Shell (bash) created as a free replacement for scripting support, job control
sh.
C Shell (csh) Introduced C-style syntax; created at Better suited for C programmers;
the University of California, supports aliases and job control
Berkeley.
Z Shell (zsh) A modern shell with features from Highly customizable, plugins/themes
(Oh My Zsh), better tab completion
bash, ksh, and tcsh.
Unlike the CLI, GUI shells use windows, icons, menus, and pointer devices to perform operations—ideal for users
who are unfamiliar with or prefer not to use command-line tools.
GNOME GNU Network Object Model Clean and modern UI, accessibility
Environment. Default in Ubuntu and support, extensible
others.
Cinnamon Developed by Linux Mint, user-friendly Familiar for Windows users, good for
and traditional in layout. beginners
The kernel is the core of the operating system and it is the foundation of other software that works
on top of it. It handles and hides all the complexity and underlying modules of the hardware. It is
the foundational layer on which another system operates. Let’s see some of the functions of the
kernel:
● Device Management: Manages all the device hardware parts including the device drivers,
input-output operation, and peripheral devices.
● Manage Resources: The kernel manages the processes of the CPU and all the peripheral
devices and acts as the bridge between the resources and processes.
● Memory Management: Kernel mainly manages memory and provides some benefits
● System calls: For managing the file operation, memory control, and process control kernel
receives system calls to perform requested services.
● Performation optimization: Balancing all the resources with the memory, optimizes the
system performance and boosts the system efficiency. It also schedules the task according
to the level of priority.
Types of Kernels in OS Architecture
1. Monolithic
2. Microkernel
3. Hybrid
4. Nano kernel
5. Exo kernel
Linux includes a monolithic kernel which makes this OS the most stable and fast
1. Monolithic Kernel
In a monolithic kernel, all essential operating system services (like memory management, file
system, device drivers, and process scheduling) run in a single large block of code in the same
memory space (kernel space).
● Disadvantages: Difficult to maintain or debug; a bug in one part can crash the whole
system.
2. Microkernel
A microkernel keeps only the most essential functions (like basic inter-process communication
and CPU scheduling) in kernel space. Other services, such as device drivers and file systems, run
in user space.
● Advantages: More stable and secure; system crashes are less likely to affect the entire OS.
● Disadvantages: Slower due to context switching between user and kernel space.
● Examples: Minix, QNX, L4, Mach (used in early macOS)
3. Hybrid Kernel
A hybrid kernel combines features of both monolithic and microkernels. It runs some services in
kernel space (for performance) and others in user space (for modularity and stability).
● Examples: Windows NT (used in Windows 10/11), XNU (used in macOS), modern Linux
(arguably has hybrid traits)
4. Exokernel
An exokernel is an experimental type of kernel that provides minimal abstraction over hardware. It
allows applications to directly manage hardware resources with minimal intervention from the OS.
A nanokernel is even smaller than a microkernel and only includes the most basic hardware
abstractions, often used as a base for other kernels or hypervisors.
The Linux File Hierarchy Structure, or Filesystem Hierarchy Standard (FHS), defines the
directory layout and contents in Unix-like operating systems. Maintained by the Linux Foundation,
FHS ensures consistency across distributions.
In Linux, all files and directories are organized under a single root directory /, regardless of
whether they reside on physical or virtual storage. Some directories may only appear if specific
subsystems (e.g., the X Window System) are installed.
While many of these directories are common across UNIX systems, the descriptions below follow
the FHS used specifically in Linux.
1. / (Root)
○ The top-level directory in the file system.
○ All other directories branch from this root.
Only the root user can write to this directory.
○ /root is the root user's personal home directory — different from /.
2. /bin
○ Contains essential binary executables needed by all users.
○ Includes common commands like ls, cp, mv, grep, and ping.
3. /boot
○ Stores files required to boot the system, such as the kernel and GRUB configuration.
○ Examples: vmlinuz, initrd.img, grub/.
4. /dev
○ Contains device files that act as interfaces to hardware.
○ Includes block devices (e.g., /dev/sda1) and character devices (e.g., /dev/tty1).
5. /etc
○ Stores system configuration files and scripts.
○ Includes startup/shutdown scripts and user-related settings.
○ Example: /etc/passwd, /etc/hosts.
6. /home
○ Contains personal directories for each non-root user.
○ Example: /home/anshu, /home/kishlay.
7. /lib
○ Holds shared libraries required by programs in /bin and /sbin.
○ Examples: ld-2.31.so, libc.so.
8. /media
○ Temporary mount point for removable media like USB drives and CDs.
Example: /media/cdrom, /media/usb.
9. /mnt
○ A generic mount point used by system administrators for mounting filesystems
temporarily.
10. /opt
○ Stores third-party applications and their data/configuration.
○ Example: /opt/google/chrome/.
11. /sbin
○ Contains system administration binaries, often requiring root privileges.
○ Example commands: fdisk, ifconfig, reboot, iptables.
12. /srv
○ Stores service-related data, such as websites and FTP files.
Example: /srv/www, /srv/ftp.
13. /tmp
○ Temporary file storage used by programs during execution.
○ Files are typically deleted at reboot.
14. /usr
○ Secondary hierarchy for user applications and data.
○ Subdirectories include:
■ /usr/bin: User commands not essential for booting.
■ /usr/sbin: Admin tools not required during boot.
■ /usr/lib: Libraries for /usr/bin and /usr/sbin.
■ /usr/local: Locally compiled programs (e.g., from source).
■ /usr/src: Kernel source and header files.
15. /proc
○ A virtual (pseudo) filesystem that provides real-time information about system and
processes.
○ Examples:
■ /proc/meminfo: Memory usage.
■ /proc/uptime: System uptime.
■ /proc/[pid]: Info about a specific process.
Navigation in Linux
Navigating the Linux file system is done using terminal commands. Here are some basic navigation
commands:
Understanding the structure and navigation commands is crucial for working effectively in a Linux
environment.
File and Directory Operations
File and Directory Operations
● Linux uses a hierarchical file system structure starting from the root directory (/), where all files and
directories reside.
● Everything in Linux is treated as a file, including devices, directories, and even processes.
● Managing files and directories efficiently is essential for any Linux user or administrator.
● Linux supports multiple users, so it uses a permission system to control access to files and directories.
● User Categories:
○ Owner: The user who owns the file.
○ Group: A set of users grouped together; the file has a group owner.
○ Others: All other users on the system.
● Types of Permissions:
○ Read (r): Permission to view the contents of a file or list a directory.
○ Write (w): Permission to modify or delete the contents of a file or directory.
○ Execute (x): Permission to run a file as a program or enter a directory.
● Permissions are shown using ls -l, which displays a 10-character string:
○ The first character indicates file type (- for file, d for directory).
○ The next nine characters represent permissions in three groups of three: user, group, others.
Example: -rwxr-xr-- means the owner can read, write, and execute; group can read and execute;
others can only read.
5. Importance of Permissions
● Proper permissions prevent unauthorized users from reading or modifying sensitive data.
● Permissions ensure system security and stability, especially on multi-user or server environments.
● Misconfigured permissions can lead to security vulnerabilities or accidental data loss.
● Beyond traditional permissions, Linux supports Access Control Lists (ACLs) for more fine-grained control.
● Security frameworks like SELinux provide mandatory access controls to further restrict program and user
capabilities.
Linux Booting Porcess
Linux Booting Porcess
When you turn on a Linux system, it goes through several steps to become ready for you to use. Here's
the complete process explained in simple words, from pressing the power button to seeing the login
screen.
BIOS (Basic Input Output System) or UEFI (Unified Extensible Firmware Interface on modern systems)
is built into your motherboard.
It performs:
● POST (Power-On Self Test) to check hardware (RAM, keyboard, storage, etc.).
● Finds the bootable device, such as your hard drive or SSD.
● Hands over control to the bootloader, typically via the MBR or EFI partition.
🧠 Think of BIOS/UEFI as the computer's gatekeeper, ensuring all hardware is okay before
handing off control.
MBR (Master Boot Record) is the first sector (only 512 bytes!) of your hard disk.
It contains:
● A tiny program that locates and starts the bootloader (usually GRUB).
● The partition table, which tells how your disk is divided.
🧠 The MBR acts like a signpost — it knows where the boot loader is and points the system to it.
Note: On UEFI systems, the bootloader is located in the EFI partition instead of using MBR.
🧠 GRUB is like a menu waiter, bringing the kernel and helping it start with the right options.
🧠 The kernel connects hardware with software, making your system functional.
The first process started by the kernel is called init (PID 1). Most modern distros use systemd instead.
It:
● runlevel 3 → multi-user.target
● runlevel 5 → graphical.target
● If using GUI: a display manager like GDM, LightDM, or SDDM shows the graphical login
screen.
● If using text mode: a login prompt appears in the terminal (TTY).
After login, your desktop environment or shell session starts, and you can now use the Linux
system!
User Managment
User Management
Each user in Linux is assigned a User ID (UID) and associated information stored in system files like /etc/passwd.
0 Root (superuser)
1 – 999 System/service
accounts
1000+ Normal user accounts
● Each user also belongs to a Group ID (GID) which defines group-based access.
👥 User Groups
Linux uses groups to simplify permission management for multiple users.
1. Primary Group:
○ Every user has one default group (usually same as their username).
○ Files created by the user are assigned to this group.
2. Secondary Groups:
○ Users can be part of additional groups.
○ Useful for granting shared access to resources like software, devices, or directories.
Example:
To add a user to a group:
bash
CopyEdit
sudo usermod -aG groupname username
● /etc/passwd: Stores user details (username, UID, GID, home directory, shell).
● /etc/shadow: Stores encrypted passwords.
● /etc/group: Contains group information.
3. Add a user:
useradd username – Creates a new user account.
4. Assign a password:
passwd username – Sets or changes the password for a user.
5. Delete a user:
userdel -r username – Deletes the user and their home directory.
2. Account lockouts:
usermod -U username – Unlocks a locked user account.
3. Security vulnerabilities:
apt update && apt upgrade – Keeps the system up to date and secure.
4. Permission errors:
chmod / chown – Fixes file or folder access issues.
https://www.geeksforgeeks.org/linux-unix/user-management-in-linux/
Group Managment
Group Managment
Group management in Linux helps in organizing users into logical units, allowing administrators to assign
permissions and control access to files and system resources efficiently.
Create a new groupadd Adds a new group with a unique Group ID.
group group_name
Example groupadd Group1 Creates a group named Group1.
Example:
gpasswd Group1
Example:
usermod -G group1 John_Doe
Example:
gpasswd -M Person1,Person2,Person3 Group1
Example:
gpasswd -d Person1 Group1
Delete a Group
Example:
groupdel Group1
File Permission and Security
File Permission and Security
● Read (r): View the contents of a file or list the contents of a directory.
Letter Meaning
w Write or modify
Example Output:
csharp
CopyEdit
-rw-r--r-- 1 user group 46 Apr 14 16:37 NarX.txt
Breakdown:
bash
CopyEdit
namei -l /path/to/your/file
🔍 Method 3: stat
Gives detailed file metadata.
bash
CopyEdit
stat hoops
Example Output:
yaml
CopyEdit
File: hoops
Size: 2210 Blocks: 8 IO Block: 4096 regular file
Access: 2024-11-18 10:50:56.000000000 +0000
Modify: 2024-11-18 10:50:56.000000000 +0000
Change: 2024-11-18 10:50:56.000000000 +0000
Examples:
bash
CopyEdit
chmod o+x xyz.txt # Add execute to others
chmod ugo-rwx xyz.txt # Remove all permissions for everyone
chmod ug+rw,o-x abc.mp4 # Add read/write to user & group; remove exec from
others
chmod ug=rx,o+r abc.c # Set read+exec for user/group, read for others
🔢 Octal Notation
Permissions are represented using numbers:
Permissio Binary Octal
n
--- 000 0
--x 001 1
-w- 010 2
-wx 011 3
r-- 100 4
r-x 101 5
rw- 110 6
rwx 111 7
Examples:
bash
CopyEdit
chmod 777 file.txt # rwx for user, group, others
chmod 755 file.txt # rwx for user, rx for group and others
chmod 435 file.txt # r for user, wx for group, rx for others
Sectio Meaning
n
rw- User can read/write
bash
CopyEdit
chmod u+s program
🛡 setgid (Set Group ID)
Files: Run as group.
Directories: New files inherit the directory's group.
bash
CopyEdit
chmod g+s directoryname
🛡 Sticky Bit
Allows only the file’s owner to delete it in a shared directory.
bash
CopyEdit
chmod +t directoryname
7. Changing Ownership
🔧 chown: Change file owner/group
bash
CopyEdit
chown user:group file.txt
User Categories:
🔐 Permission Types:
Example:
🔧 Important Commands:
Text editors are used to write or edit text files. Linux provides both command-line and graphical text editors.
● nano:
○ Has two modes: insert mode (for writing) and command mode (for editing and saving).
🔹 1. cat:
🔹 2. less:
🔹 3. more:
🔹 4. head:
🔹 5. tail:
📌 Additional Points:
● These tools are lightweight and fast.
● Support shell scripting, configuration file editing, and log file monitoring.