Linux Full Course: Theory to Practice
Comprehensive Linux training covering history and evolution from Unix, core concepts (kernel, shell, file systems), practical commands, package management, administration, shell scripting, and comparisons with Windows and Unix. Includes 60+ interview questions with answers.
Linux History and Evolution
Birth of Unix and C Programming (1969)
Dennis Ritchie and Ken Thompson created the C programming language and Unix operating system at AT&T Bell Labs in 1969. Unix became the foundation for modern operating systems and influenced the development of Linux decades later.
Open Source Collaboration vs. Commercial Unix
In the 1970s, Unix development was collaborative and open, but AT&T commercialized it, creating tension. This led developers to create their own Unix variants (AIX, Solaris, HP-UX) in the 1980s, fragmenting the ecosystem.
GNU Project and Free Software Movement
Richard Stallman launched the GNU project in the mid-1980s to create a free, open-source Unix-like operating system. GNU stands for 'GNU's Not Unix' (recursive acronym). Combined with Linus Torvalds' Linux kernel in the 1990s, it created modern Linux distributions.
Linux Fundamentals and Architecture
What is Linux: Kernel vs. Operating System
Linux is a kernel (core software managing hardware-software communication), not a complete operating system. A Linux distribution combines the Linux kernel with GNU utilities and libraries to create a full OS. Examples include Ubuntu, CentOS, Debian, and Fedora.
Major Linux Distributions
Red Hat Enterprise Linux and Fedora are commercially backed by Red Hat; Debian is community-developed; Ubuntu (based on Debian) is the most popular for desktops. CentOS is a free Red Hat variant. Each offers different stability, speed, and support levels.
Linux Kernel: Core of the OS
The Linux kernel (13+ million lines of code) is the lowest-level software interfacing with hardware. It translates user commands into machine language and manages all processes, memory, and hardware communication. It is the heart of any Linux operating system.
Key Features of Linux
Easy Updates and Free Software
Linux allows simple one-command updates for software and the OS itself. Unlike Windows (which requires licensing), Linux is completely free with no licensing costs, making it ideal for companies and developers.
Open Source and Source Code Access
Linux source code is freely available for modification and customization. Users can change the OS behavior, add features, and share improvements with the community. Windows does not offer this flexibility.
Superior Security and Malware Protection
Linux requires no antivirus software and is significantly more secure than Windows. The open-source model allows security experts worldwide to identify and patch vulnerabilities rapidly. Linux is the OS of choice for servers due to stability and security.
Multiple Distributions and Flexibility
Nearly 100 Linux distributions exist, offering flexibility without cost or learning curve. Commands are 98% identical across distributions, allowing easy switching between Ubuntu, CentOS, Debian, etc. based on preferences.
Command Line Interface (CLI) Advantage
Linux provides both GUI and powerful CLI (terminal). The CLI enables complex tasks in single commands, faster execution, and remote server management. This is why developers prefer Linux over Windows.
Linux File System and Directory Structure
Root Directory and Hierarchical File System
Linux uses a tree-like hierarchical file system starting from the root directory (/) rather than Windows drive letters (C:, D:). All files and directories branch from root. Everything in Linux is a file, including directories and devices.
Key Linux Directories
Important directories include /home (user files), /bin (executables), /etc (configuration files), /lib (libraries), /dev (devices), /root (root user home), /var (variable data), and /usr (user programs). Understanding this structure is essential for navigation.
File Permissions: Read, Write, Execute
Linux has three permission levels: read (4), write (2), execute (1). Permissions apply to owner, group, and others. Permissions are displayed as rwx (symbolic) or numbers like 755 (absolute mode). Use chmod to change permissions.
Symbolic Links (Soft Links) vs. Hard Links
Symbolic links are shortcuts pointing to files/directories (like Windows shortcuts) but don't contain data. Hard links create additional directory entries for the same file with the same inode. Soft links can span file systems and work for directories; hard links cannot.
Inodes: File Metadata Storage
An inode stores file metadata (size, permissions, ownership, timestamps, link count) but not file content. File content is stored in data blocks. Each file has a unique inode number. Different files have different inodes even if linked.
Essential Linux Commands
Navigation Commands: pwd, cd, ls
pwd (print working directory) shows current location. cd (change directory) moves between folders; cd .. goes to parent, cd ~ goes to home, cd / goes to root. ls lists directory contents; ls -l shows detailed permissions, ls -a shows hidden files.
File Viewing: cat, vi, nano
cat displays file contents and can concatenate multiple files. vi is a powerful text editor with insert/command modes. nano is simpler for beginners. cat can redirect output to files using > (overwrite) or >> (append).
Search and Filter: grep
grep searches for strings/patterns in files. grep -i searches case-insensitively, grep -n shows line numbers, grep -c counts matches, grep -v shows non-matching lines. Essential for finding specific content in large files.
Sorting and Redirection
sort arranges file contents alphabetically or numerically; sort -r reverses order. Redirection uses > (output to file, overwrites), >> (append), and | (pipe output to another command). These enable command chaining and data manipulation.
User and Permissions: su, sudo, chmod, chown
su switches to root user (requires password). sudo executes single command as root. chmod changes file permissions (e.g., chmod 755 file). chown changes ownership. These are critical for system administration and security.
Echo and Variables
echo prints text or variable values to output. Variables are accessed with $ prefix (e.g., $X prints variable X). echo is used in scripts for output and in redirection to create files with content.
Advanced Linux Concepts
Shell: User Interface to OS
A shell is a command language interpreter providing user interface to the OS. bash (Bourne Again Shell) is the default Linux shell. Shells interpret commands, manage variables, and support scripting. bash features include command aliasing, tab completion, and history.
Daemons: Background Services
Daemons are background processes providing system services (mail, web servers, logging). They have no controlling terminal (TTY shows ?), start at boot, and typically end with 'd' (e.g., syslogd). Essential for server operations.
Package Management: yum, apt-get
Package managers install, update, and remove software. Red Hat systems use yum; Debian systems use apt-get. Commands like yum install [package] or apt-get update manage software dependencies automatically.
Swap Space: Virtual Memory
Swap space on disk extends RAM when physical memory is full. Inactive pages move from RAM to swap, improving performance on low-memory systems. Recommended swap size is twice physical RAM; not needed on servers with abundant RAM.
Process Management: ps, kill, nice, renice
ps lists running processes with status (S=sleep, R=running, Z=zombie). kill terminates processes. nice sets process priority (-20 to 19; -20 is highest). renice changes priority of running processes. Essential for system monitoring.
Logical Volume Manager (LVM)
LVM enables flexible storage management with resizable logical volumes. Unlike fixed partitions, LVM volumes can be shrunk or expanded without data loss. Requires unmount, fsck check, resize2fs, and lvreduce commands.
Environment Variables
Environment variables store system settings (PATH, HOME, SHELL, USER). System variables are set by OS; user-defined variables are custom. env command displays all variables. Used to pass information to processes and configure shell behavior.
Users and Permissions: Regular, Root, Service
Linux has three user types: regular users (limited access, home directory in /home), root (superuser with all privileges), and service users (for running services). Root can access all files and install software. Regular users cannot modify system files.
Shadow Passwords for Security
Shadow passwords store encrypted passwords in /etc/shadow (readable only by root) instead of /etc/passwd (world-readable). This prevents unauthorized password access and improves multi-user system security.
Shell Scripting Fundamentals
Shell Script Basics
Shell scripts are text files containing commands executed sequentially by the shell. Start with #!/bin/bash shebang. Variables are assigned without spaces (X=100), accessed with $X. Scripts enable automation of repetitive tasks.
Conditional Logic: if-then-fi
if-then-fi statements execute commands based on conditions. Syntax: if [ condition ]; then commands; fi. Test conditions include -d (directory exists), -f (file exists), -eq (equal), -ne (not equal). Essential for decision-making in scripts.
Loops: for and while
for loops iterate over lists: for i in 1 2 3; do commands; done. while loops repeat while condition is true: while [ condition ]; do commands; done. Enable repetitive operations on multiple items.
Functions in Shell Scripts
Functions group commands for reuse. Syntax: function_name() { commands; }. Called by name. Parameters passed as $1, $2, etc. Return values with return statement. Improve script organization and maintainability.
Debugging: set -x
set -x enables debugging mode, showing each executed line prefixed with +. Helps identify script errors and logic issues. Disable with set +x. Essential for troubleshooting complex scripts.
Linux vs. Windows Comparison
Market Share and Usage
As of 2007, Windows dominated with 92% of PC market share vs. 1% for Linux. However, Linux dominates servers and supercomputers. Most internet giants (Google, Facebook) run on Linux. Linux is preferred for serious server applications.
Kernel Architecture
Linux uses monolithic kernel (larger, more efficient) consuming more memory. Windows uses microkernel (smaller, modular) consuming less memory but with lower system efficiency. Linux is generally faster for server workloads.
File System Structure
Windows stores files in folders on drives (C:, D:). Linux uses tree-like structure from root directory (/). Linux treats everything as files (directories, devices). More unified and flexible approach.
Security and Stability
Linux is more stable and secure than Windows. Windows faces frequent security issues, viruses, and blue screens of death. Linux is community-monitored with rapid threat fixes (hours vs. Windows monthly patches). Multi-user Unix architecture provides better isolation.
Software Compatibility
Windows has superior compatibility with most commercial software. Linux struggles with some proprietary applications (Adobe Flash, Microsoft Office). However, Linux can read/write NTFS and FAT formats; Windows cannot read ext4.
Ease of Use
Windows is default for most users due to market proliferation. Linux distributions (Ubuntu, Mint) have improved usability significantly. Linux Mint offers Windows-like interface. Both support multimedia, but Linux has more free applications.
Privacy and Source Code
Linux is private with no spying or telemetry. Windows increasingly includes ads and telemetry (OneDrive sync, Cortana). Linux source code is open and auditable; Windows is proprietary. Linux offers military-grade encryption.
Licensing and Cost
Linux is completely free to download and use. Windows costs $99-199 per license. Linux companies offer optional paid support, but software remains free. Significant cost savings for enterprises.
Reliability and Uptime
Linux servers run for years without reboots. Windows requires frequent reboots for updates and maintenance. Linux is the OS of choice for critical infrastructure due to reliability. Supercomputers and data centers predominantly use Linux.
Developer Experience
Linux is superior for developers. Native support for Python, C, C++, Java, Perl, Ruby. Bash scripting is powerful for automation. Package managers (apt-get) simplify dependency management. SSH native support for server management.
Gaming and Graphics
Windows dominates gaming with Steam and AAA titles. Linux gaming is limited; Steam for Linux is still in beta. Graphics card vendors prioritize Windows drivers. Linux users miss out on top games.
Linux vs. Unix Comparison
Usage and Development
Unix is used in internet servers and workstations. Linux is used by everyone from home users to enterprises. Unix development is by AT&T and commercial vendors. Linux development is open-source with thousands of collaborators.
Architecture and Processors
Unix runs on PA-RISC, Titanium, SPARC, Power, x86/x64. Linux originally for Intel 386, now supports 50+ CPU types including ARM. Linux has wider processor support.
File System Support
Unix supports ZFS, HFS+, GPS, XFS, VxFS. Linux supports XFS, NFS, Ext2-4, BTRFS, NTFS. Linux offers broader file system compatibility.
Shell and GUI
Unix originally used Bourne shell; now supports multiple shells. Linux defaults to bash. Unix has CDE and GNOME GUIs. Linux offers KDE, GNOME, MATE, XFCE, and many alternatives.
Portability and Licensing
Unix is not portable. Linux is portable and boots from USB. Unix has different pricing by vendor. Linux is freely distributed or cheaply licensed. Linux is more accessible.
Security and Threat Response
Unix: 80-120 viruses reported, longer wait for patches. Linux: 60-100 viruses reported, not spreading, rapid community-driven fixes (hours). Linux threat detection is faster.
Source Code Availability
Unix source code is proprietary and not available. Linux source code is open and available to the public. This enables rapid bug fixes and security improvements in Linux.
System Administration and Monitoring
Memory and CPU Monitoring
free -M/-G shows memory usage in MB/GB. vmstat displays virtual memory statistics. sar (System Activity Report) shows CPU usage and memory. Essential commands for performance monitoring and troubleshooting.
Disk Space Management
df shows disk usage by file system. du shows directory usage. du -sh [directory] shows total size. Essential for capacity planning and identifying space hogs.
Device Naming Conventions
IDE drives: /dev/hda, /dev/hdb. SATA/SAS drives: /dev/sda, /dev/sdb. Partitions: /dev/sda1, /dev/sda2. Floppy drives: /dev/fd0, /dev/fd1. Serial ports: /dev/ttyS0, /dev/ttyS1. Printer ports: /dev/lp0, /dev/lp1.
Backup Types: Full and Partial
Full backup includes entire file system. Partial backup includes selected files/folders. Tools: tar, cpio, dump, restore. Partial backups save time and storage but require careful planning.
File Name and Path Limits
Maximum file name length: 255 characters. Maximum path length: 4096 characters. Applies to ext3, ext4, and most modern file systems.
Interview Questions and Practical Skills
What is Linux?
Linux is a free, open-source operating system kernel developed by Linus Torvalds. Combined with GNU utilities, it forms complete Linux distributions. Used by developers, servers, and enterprises for stability, security, and flexibility.
Linux Bootloader: LILO and GRUB
LILO (Linux Loader) is an older bootloader loading Linux into memory at startup. GRUB (Grand Unified Bootloader) is the modern default, more flexible and customizable. GRUB2 is the latest version with enhanced features.
Command Chaining and Piping
Multiple commands executed sequentially using semicolon (;). Pipe (|) passes output of one command as input to another. Example: ls -l | grep .txt pipes file listing to grep for filtering.
Finding Files with Specific Content
find /path -name '*.txt' -exec grep -l 'pattern' {} \; searches for .txt files containing 'pattern'. Combines find with grep for powerful file searching.
Process Status Codes
S = interruptible sleep (waiting for event). D = uninterruptible sleep (waiting for I/O). R = running. Z = zombie (terminated but not reaped). T = stopped. > = high priority. N = low priority. L = pages locked in memory.
Hidden Files and Dot Notation
Files prefixed with dot (.) are hidden. Examples: .bashrc, .cache. Hidden files are configuration files. ls -a shows hidden files. Often contain important system or user settings.
Virtual Desktops and Desktop Virtualization
Virtual desktop stores user desktop environment on remote server rather than local PC. Tools: VMware, VirtualBox, Hyper-V. Benefits: cost savings, resource sharing, centralized administration, improved data integrity.
Creating Directories and Files
mkdir creates directories. Files created with cat, vi, nano, gedit, or redirection (>). Example: mkdir dir1 creates directory; cat > file.txt creates file.
Real Number Calculations with bc
bc is a calculator for floating-point arithmetic. Usage: echo '4.5 + 3.2' | bc. Requires bc package installed. Useful for shell scripts needing decimal calculations.
Getting Pi to 100 Decimal Places
echo 'scale=100; 4*a(1)' | bc -l calculates pi to 100 decimal places using bc math library. scale parameter sets precision.
Checking Directory Existence in Scripts
if [ -d /path/to/dir ]; then echo 'exists'; fi checks if directory exists. -d flag tests directory existence. Essential for conditional logic in scripts.
Reversing Numbers with Shell Script
Algorithm: extract digits using modulo, build reverse number iteratively, print result. Demonstrates loops, variables, and arithmetic in shell scripts.
Running Programs in Background
nohup command runs process in background, immune to terminal logout. Example: nohup program & runs program in background. Essential for long-running tasks.
Finding Total Disk Space Used by User
du -sh /home/username shows total disk usage for user. du command recursively calculates directory sizes. -s shows summary, -h shows human-readable format.
Notable quotes
Linux is a Linux clone written from scratch by Linus Torvalds with assistance from hackers across the net. — Course instructor
Linux is the OS of choice for server environments due to its stability and reliability. — Course instructor
With Linux being open source, several distributions are available to the end user completely free to download. — Course instructor
Action items
- Install a Linux distribution (Ubuntu or CentOS recommended) on a virtual machine using VirtualBox
- Practice basic commands: pwd, cd, ls, cat, grep, sort, chmod in a terminal
- Create and modify files using vi, nano, or cat with redirection
- Write a simple shell script with variables, conditionals (if-then-fi), and loops
- Monitor system performance using free, vmstat, sar, and du commands
- Create symbolic links and understand file permissions with chmod and chown
- Set up user accounts and practice switching between users with su and sudo
- Create a logical volume with LVM and practice resizing it
- Write a shell script to search for files with specific content using find and grep
- Practice command chaining and piping with multiple commands