Opened Blog

Linux: An Overview

Linux

This guide provides a structured overview of Linux essentials for developers. Below is the index to help you navigate through different sections.

A Brief History of Linux

Linux originated from Unix, developed in the 1960s at Bell Labs, which laid the foundation for portable, multi-tasking, and multi-user systems. However, Unix's proprietary licensing limited its accessibility.
In 1991, Linus Torvalds introduced Linux as a free and open-source operating system, fostering global collaboration and innovation. Today, Linux powers servers, desktops, and even mobile devices like Android.

Popular Linux Distributions

Linux offers a variety of distributions (distros) tailored for different use cases, from development to security testing. Here are some of the most popular options:

  • Ubuntu: Beginner-friendly, extensive community support, and great for desktop and server use.
  • Fedora: Cutting-edge technology, frequent updates, and a focus on open-source software.
  • Arch Linux: Lightweight and customizable, aimed at experienced users with a focus on simplicity.
  • Linux Mint: Designed for ease of use, perfect for users transitioning from Windows.
  • Pop!_OS: Developer-focused, gaming-friendly, and well-optimized for System76 hardware.
  • Kali Linux: Security and penetration testing tools pre-installed for ethical hackers.
  • Parrot OS: Similar to Kali but lightweight, with tools for penetration testing and digital forensics.

Installing Fedora and Arch Linux

Let's walk through the installation process for Fedora and Arch Linux.

Fedora Installation

  1. Download the Fedora ISO from the official website.
  2. Create a bootable USB using tools like Rufus (Windows) or dd (Linux):sudo dd if=fedora.iso of=/dev/sdX bs=4M status=progress
  3. Boot from the USB, select "Install Fedora," and follow the graphical installer.
  4. Set up partitions (automatic or manual), choose your time zone, and create a user account.
  5. Reboot, remove the USB, and enjoy Fedora!

Arch Linux Installation

  1. Download the Arch ISO from the official website.
  2. Create a bootable USB using dd as shown above.
  3. Boot from the USB and access the terminal. Run:cfdiskto partition the disk, setting up EFI, swap, and root partitions.
  4. Format the partitions using mkfs.ext4 and mkswap, then mount them.
  5. Install essential packages:pacstrap /mnt base linux linux-firmware
  6. Generate an fstab file and configure your system:genfstab -U /mnt >> /mnt/etc/fstab
  7. Chroot into the system, set up a bootloader, and reboot.

Directories in Linux

User Directories

  • ~/.config: Stores user-specific configuration files for various applications.
    • Desktop environment settings (GNOME, KDE).
    • Application preferences (e.g., text editors, media players).
  • ~/.local/share: Contains user-specific application data.
    • ~/.local/share/flatpak: Data for Flatpak-installed apps.
    • Plugins, themes, and runtime data.
    • Game save files or runtime data.
  • ~/.cache: Stores cached data for applications to improve performance.
    • Browser caches (e.g., Firefox, Chromium).
    • App-specific caches for faster startup.
  • ~/.bashrc, ~/.zshrc, etc.: Shell configuration files for customizing behavior.
    • Include aliases, environment variables, and shell functions.
  • ~/.mozilla, ~/.steam, etc.: App-specific directories for data storage.
    • ~/.mozilla: Firefox browser data.
    • ~/.steam: Steam gaming platform data.

System Directories

  • /: The root directory, the top-level directory of the Linux filesystem.
  • /bin: Essential binaries needed by all users (linked to /usr/bin).
  • /boot: Boot loader files, including GRUB and kernel images.
  • /dev: Device files representing hardware and peripherals (e.g., /dev/sda).
  • /etc: Configuration files for system-wide settings and installed applications.
  • /home: User home directories for personal files and settings.
  • /lib and /lib64: Shared libraries and kernel modules (linked to /usr/lib).
  • /media: Mount points for removable media like USB drives and CDs.
  • /mnt: Temporary mount points for filesystems.
  • /opt: Optional software installed by the user or system administrator (e.g., third-party tools).
  • /proc: A virtual filesystem for process and kernel information.
    • /proc/cpuinfo: CPU details.
    • /proc/meminfo: Memory usage.
  • /root: Home directory for the root user (superuser).
  • /run: Runtime data for processes and services since the last boot.
  • /sbin: System administration binaries (linked to /usr/sbin).
  • /usr: User system resources.
    • /usr/bin: Commands for general users.
    • /usr/sbin: Commands for system administration.
    • /usr/lib: Libraries for installed software.
    • /usr/share: Shared data like icons, documentation, and themes.
  • /var: Variable data like logs, caches, and databases.

Essential Terminal Commands

The terminal is one of the most powerful tools in Linux, enabling users to interact directly with the system. Below are some of the essential terminal commands every Linux user should know:

  • man command-name: Open the manual for a specific command. Example: man ls.
  • whatis command-name: Get a brief explanation of a command. Example: whatis grep.
  • whereis file/command: Locate the binary, source, and manual for a file or command. Example: whereis bash.
  • ls: List files and directories.
    • -a: Show hidden files.
    • -l: Show detailed information.
    • Example: ls -al.
  • cd: Change the current directory. Example: cd /home.
  • mkdir: Create a new directory. Example: mkdir new-folder.
  • rm: Remove files or directories.
    • -r: Recursively delete a directory.
    • -f: Force deletion without prompts.
    • Example: rm -rf unwanted-folder.
  • cat: Display the content of a file. Use bat (if installed) for syntax highlighting. Example: cat file.txt.
  • grep: Search for a pattern in a file or output. Example: grep "error" log.txt.
  • find: Search for files in a directory hierarchy. Example: find / -name "filename*".
  • chmod: Change file permissions. Example: chmod 755 script.sh.
  • htop: Interactive process viewer for managing and monitoring system resources.
  • kill: Terminate a process by its ID (PID). Example: kill -9 1234.
  • tar: Archive and extract files.
    • -cvf: Create an archive.
    • -xvf: Extract an archive.
    • Example: tar -cvf archive.tar folder.
  • df: Check disk space usage. Example: df -h (human-readable format).
  • pushd / popd: Navigate directories using a stack-like structure.
  • scp: Securely copy files between systems. Example: scp file.txt user@remote:/path.
  • sudo: Run commands with administrative privileges. Example: sudo apt update.
  • history: Show a history of commands entered in the terminal.
  • alias: Create shortcuts for commands. Example: alias ll="ls -al".
  • exit: Close the terminal session.

Mastering these commands will help you manage files, processes, and configurations more efficiently. Experiment with these to better understand the Linux system.

Bash

Bash, the Bourne Again Shell, is the default shell in most Linux distributions. It’s a powerful tool that can significantly enhance your productivity with automation and scripting. Here’s a simple example to get you started:

#!/bin/bash
# A simple backup script
SOURCE_DIR="/home/infernitex/documents"
BACKUP_DIR="/home/infernitex/backups"
DATE=$(date +%F)

# Create a backup
mkdir -p "$BACKUP_DIR"
cp -r "$SOURCE_DIR" "$BACKUP_DIR/backup-$DATE"

echo "Backup completed successfully!"

This script demonstrates how to use variables, date commands, and file operations in Bash to automate a backup. Run it using bash backup.sh, and watch Bash handle the rest!

PS: While Bash is a solid and versatile shell, you might also encounter other popular shells like Zsh and Fish. Here’s how they compare to Bash:

  • Zsh: Known for its extensive customization options and modern features. It supports plugins like oh-my-zsh, which enhance the shell’s functionality with themes, auto-suggestions, and more.
  • Fish: Designed for user-friendliness, Fish (Friendly Interactive Shell) has built-in features like syntax highlighting and autosuggestions without requiring external plugins.

Each shell has its strengths. Bash is widely supported and ideal for scripting, while Zsh and Fish focus more on an interactive and user-friendly experience. Explore and choose the one that fits your workflow!

Tiling Window Managers

Tiling window managers (TWMs) organize application windows in non-overlapping tiles for better productivity and minimalism. These are highly configurable and cater to developers who prefer keyboard-driven workflows.

  • i3 (Debian, Arch, Fedora): Lightweight and configurable.
    • Pros: Easy to configure, fast, great for scripting.
    • Cons: Lacks out-of-the-box features; requires initial setup.
  • AwesomeWM (Arch, Fedora): Highly extensible and Lua-based.
    • Pros: Powerful customization, community-driven modules.
    • Cons: Steeper learning curve.
  • Sway (Wayland-based): A modern TWM for Wayland systems.
    • Pros: Smooth Wayland support, feature-rich.
    • Cons: Limited support for older X11 apps.

Terminal Tools for Productivity

Linux offers powerful tools to enhance terminal workflows. Some must-know tools include:

  • tmux: A terminal multiplexer to manage multiple terminal sessions. (Blog coming soon!)
  • fzf: A fast, interactive fuzzy finder for searching files, directories, and commands.
  • ripgrep (rg): A blazing-fast search tool for searching within files.
  • bat: A modern alternative to cat with syntax highlighting.
  • ncdu: An interactive disk usage analyzer.