Comprehensive Linux OS and Administration Guide
Introduction to Linux and Basic Components
What is Linux? * Linux is an Operating System (OS) similar to Windows or macOS. * It is open-source, meaning the source code is publicly available and completely free to use. * Application areas include servers, cloud computing, mobile devices (Android), embedded systems, and DevOps tools.
Basic Components of the Linux OS * Kernel: The core part of the operating system that communicates directly with the hardware such as the CPU, RAM, and disks. * Shell: A program that allows users to interact with the OS by typing commands. * File System: Organizes and stores data. A key tenet of Linux is that everything is treated as a file, including hardware devices. * GUI (Graphical User Interface): This is optional. Linux can utilize environments like GNOME or KDE, though it is frequently used via the terminal.
Linux Directory Structure
The Linux file system starts at the root () directory. Folders beneath it serve fixed purposes:
- : The root of the entire file system.
- : Contains user folders (analogous to C:\Users in Windows).
- : Essential command binaries needed for basic operations (e.g., , , ).
- : Houses system configuration files.
- : Stores variable files, such as system logs.
- : Temporary files that are often cleared upon reboot.
- : User programs and libraries.
- : The home directory specifically for the root (administrative) user.
- : Files representing hardware devices like USB drives and hard disks.
- : A virtual folder containing system and process information.
Basic Linux Commands and Operations
- Navigation and File Management: * : Show current working directory. * : List files and folders. * : Change directory. * : Create a new directory. * : Create an empty file. * : Copy files or folders. * : Move or rename files and folders. * : Delete files. * : Display the full contents of a file. * : Clear the terminal screen. * : Close the current terminal or shell session.
User Permissions and Ownership
Linux is a multi-user environment where every file and folder is assigned specific permissions and ownership to ensure security and isolation.
User Types: * root: The superuser with administrative privileges and full access. * Normal users: Have limited access to the system.
Permissions Categories: * Owner: The specific user who owns the file. * Group: A collection of users with shared access. * Others: Everyone else on the system.
Permission Types: * (read): Allows viewing content. * (write): Allows modifying content. * (execute): Allows running a file or entering a directory.
Example Permission String: * The first character () indicates the file type. * (owner): Full permissions (read, write, execute). * (group): Read and execute permissions only. * (others): Read-only access.
Package Management and Software Installation
Different Linux distribution families use different package managers to install, update, and remove programs:
- Ubuntu/Debian-based: Uses or .
- Red Hat/CentOS/Fedora: Uses or .
- Arch Linux: Uses .
- Universal Formats: Includes , , and .
CRUD Operations in Linux
CRUD stands for Create, Read, Update, and Delete. These operations can be performed on files, directories, content, and system records.
CREATE Operations: * Create a file: * Create a file with content (Option A): * Create a file with content (Option B): (Then type content and press to save). * Create a directory: * Create nested directories:
READ Operations: * View content: * Scrollable view: * Page-wise output: * View first lines: * View last lines: * List files: * Detailed list (permissions, size, owner): * Show hidden files: * Read specific line (e.g., line): or
UPDATE Operations: * Append to file: * Edit via terminal: (Beginner-friendly) or (Advanced). * Replace text: * Rename/Move:
DELETE Operations: * Delete file: * Delete directory: * Force delete: * Warning: Executing can wipe the entire operating system and should never be used lightly.
The VIM Editor – Modes and Operations
Vim (Vi IMproved) is a modal text editor essential for editing configuration files, shell scripts, and YAML files in headless server environments.
Primary Modes: 1. Normal Mode: The default mode used for navigation, deleting, and copying. (Enter by pressing ). 2. Insert Mode: Used for typing text. (Enter by pressing ). 3. Command-Line Mode: Used for saving, quitting, and searching. (Enter by pressing from Normal Mode).
Navigation Actions (Normal Mode): * : Left, Down, Up, Right. * : Jump to next/previous word. * 0 / \: Start/End of line. * : Top/Bottom of file.
Editing Actions (Normal Mode): * : Delete (cut) line. * : Copy (yank) line. * : Paste below/above cursor. * : Undo. * : Redo.
Command-Line Mode Utilities: * : Save. * : Quit. * or : Save and quit. * : Force quit without saving. * : Show line numbers. * : Search for a word ( for next match). * : Global find and replace.
Numeric (Octal) Permissions and chmod
Permissions are calculated using numeric values based on binary logic:
- (Read):
- (Write):
- (Execute):
Combined values (examples):
- ():
- ():
- ():
- ():
Commonly used numeric codes:
- : Everyone has full access.
- : Owner has full access; others can read and execute.
- : Only the owner has access.
- : Owner can read/write; others can only read.
- : Only the owner can read/write.
Advanced Permissions and Special Bits
- Special Permissions: * (Setuid / Setgid): Runs a program with the owner or group's privileges. * (Sticky Bit): Applied to directories (like ) to ensure only the file owner can delete their specific files.
- Directory-Specific Behavior: * : Ability to list files (). * : Ability to add or remove files. * : Ability to enter the directory ().
Linux User and Group Management
User Management Commands: * Create: (creates home directory and prompts for password). * Delete: . * Modify: (adds user to the 'devops' group). * Lock/Unlock: (Lock); (Unlock).
Information Files: * : Account details (username, UID, GID). * : Encrypted passwords. * : Group definitions. * : Permissions for sudo access.
Service Management (systemd and systemctl)
A service (or daemon) is a background process. Modern Linux distributions use for management.
Service Operations: * : Start service. * : Stop service. * : Restart service. * : Check if service is running. * : Set service to start automatically at boot.
Logs: (Follow logs for a specific unit).
Anatomy of a .service File (): * [Unit]: Description and dependencies (e.g., ). * [Service]: Defines (path to script), , , and policy (e.g., ). * [Install]: Defines the target (e.g., ).
Process Management
Process States: * R: Running * S: Sleeping * T: Stopped * Z: Zombie (terminated but not cleaned up) * D: Uninterruptible sleep (I/O wait)
Management Tools: * : Live system monitoring. * : Snapshot of all processes. * : Forcefully stop a process. * : Set process priority ( is highest, is lowest).
Networking and Connectivity
- Tools and Commands: * : View IP addresses. * : Test connectivity to a host. * : DNS troubleshooting. * : View listening ports and services. * : Test HTTP requests. * : Port scanning.
Linux Troubleshooting Checklist
- Service Status: Is the service running? ()
- Logs: Are there error messages in or ?
- Ports: Is the port listening? ()
- Resources: Is the disk full () or memory exhausted ()?
- Permissions: Does the user have ownership and correct permissions?
- Network: Can you ping the target or trace the route?
Sample Practice Exercise: File Creation and Permissions
- Setup: mkdir\,devops_practice\,&&\,cd\,devops_practice.
- Create: .
- Append Content: * *
- Edit: Use to update the IP.
- Secure: (Only owner can read/write).
- Cleanup: .