Skip to main content

Linux Basics - 01

What is Linux?

  • Kernel: The core of the operating system. It manages hardware (CPU, memory, devices) and provides services to programs.
  • Unix: A powerful, multitasking, multi-user OS that serves as the basis for many modern operating systems.
  • Linux: The kernel of a family of open-source Unix-like operating systems.

The GNU Project

  • GNU's Not Unix: Initiated in 1983 to create a free OS.
  • GPL (General Public License): Most GNU software and the Linux kernel (created by Linus Torvalds in 1991) are released under this, promoting freedom to use, modify, and distribute.
  • GNU/Linux: GNU provides the tools/utilities; Linux provides the kernel.

Linux Distributions (Distros)

Different operating systems built upon GNU/Linux to cater to specific needs.

  • Ubuntu: Part of the Debian family; designed to be user-friendly.
  • CentOS Stream: Part of the Red Hat family; used to familiarize users with RHEL (Red Hat Enterprise Linux).

Virtualization Setup

Running Linux virtualized allows for safe experimentation and the use of Snapshots (going back in time if the system is destroyed).

Processor TypeRecommended Software
Intel / AMD (x86_64)VirtualBox
Apple Silicon (M1/M2/M3)UTM (Optimized for macOS/ARM)

CPU Architectures

  • x86: Developed by Intel, widely used by AMD and Intel (64-bit version called x86_64 or amd64).
  • ARM: Dominant in mobile and now newer Macs (Apple Silicon).

Terminal Basics and Bash

Confirming the Shell

To confirm you are running Bash:

echo "${BASH_VERSION}"

If it outputs an empty line, launch it by typing bash.

The echo Command

Used to output text in the terminal.

FlagDescription
echo 'Text'Standard output with a line break.
-nDisable the trailing line break.
-eEnable backslash escapes (e.g., \n for newline).

Combining Options: You can combine flags like this:

echo -en 'Hello\nWorld'
  • Working Directory: The folder where the shell is currently operating.
  • pwd: Print Working Directory.
  • cd [directory]: Change directory.
    • cd ..: Move to parent directory.
    • cd ~ or cd: Move to user home directory.
    • cd /: Move to the system root.

Listing Contents: ls

Syntax: ls [option...] [path]

OptionDescription
-aList all entries, including hidden files (starting with .).
-tSort by time (modification time, newest first).
-rReverse order while sorting.
--colorEnables colorful output.

Color Arguments: --color={always,never,auto}

Example Usage:

# Sort by time, show hidden files, with color
ls -ta --color=auto ~/Desktop

Paths: Absolute vs. Relative

  • Absolute Paths: Start with /. Defines the complete path from the root. Works regardless of current directory.
    • Example: /home/jannis/Desktop
  • Relative Paths: Resolved based on current working directory.
    • Example: ./Desktop or ../Documents

Advanced Terminal Tips

  • Executing Multiple Commands: Use a semicolon ;.
    • Example: echo -n 'Hello '; echo 'World'
  • Getting Help:
    • [command] --help or [command] -h
    • man [command]: Access the built-in manual (e.g., man ls).

User Management and Privileges

User Categories

Linux users are generally categorized into three types:

  1. System Accounts:
    • Used for running background tasks (webservers, databases).
    • Usually do not have a home directory.
  2. Regular Users:
    • Access to their own files/directories only.
    • Cannot perform administrative tasks or access other users' files without permission.
  3. Superuser (root):
    • Unrestricted access to the entire system.
    • Can add/remove users, install software, and change system configurations.

Elevating Privileges: sudo

sudo (SuperUser DO) allows a regular user to temporarily execute commands with root privileges.

  • Example: sudo ls /root (allows access to a directory normally restricted to root).
  • Warning: Commands executed with sudo can be destructive.
    • DO NOT EXECUTE: sudo rm -rf /etc (this will delete your system configuration).

Package Management

Package management is a centralized way to install, update, and remove software. It handles dependencies automatically.

Ubuntu (Debian-based): apt

Ubuntu uses apt (Advanced Package Tool).

CommandDescription
sudo apt updateRefreshes the list of available packages (run this first!).
sudo apt upgradeUpgrades existing packages and installs required dependencies.
sudo apt full-upgradeLarge upgrade; may remove/install packages to handle dependencies.
sudo apt install [pkg]Installs a new package (e.g., sudo apt install cowsay).
sudo apt remove [pkg]Removes a package.
sudo apt autoremoveRemoves orphaned packages no longer needed.

Note: apt-get is an older implementation of the same tool and is still commonly used.

CentOS Stream (RHEL-based): dnf

CentOS uses dnf (Dandified YUM). Unlike Ubuntu, dnf refreshes its package list automatically.

CommandDescription
sudo dnf updateFetches package lists and upgrades the system.
sudo dnf upgradeSame as update in most modern RHEL contexts.
sudo dnf install [pkg]Installs a package.
sudo dnf remove [pkg]Removes a package.

Recommended Setup for CentOS: To access additional software, install the EPEL (Extra Packages for Enterprise Linux) repository:

sudo dnf update
sudo dnf install epel-release
sudo dnf update
sudo crb enable

Note: yum was the predecessor to dnf. Commands like yum install still work as aliases.


macOS : Using the Terminal

macOS comes with Bash pre-installed, but there is a version conflict:

  • Bash 3.2: Pre-installed (License: GPLv2).
  • Bash 4.0+: License changed to GPLv3, which Apple does not include in macOS.
  • Zsh: The default shell for newer macOS versions.

Installing Modern Bash (5.x)

To use the latest Bash features on a Mac, use the Homebrew package manager.

  1. Install Homebrew: Follow instructions at brew.sh.
  2. Update Homebrew: brew update
  3. Install Bash: brew install bash
  4. Upgrade Bash: brew upgrade bash

Launching Bash

  • Latest Version: Type bash in the terminal (confirm with echo "${BASH_VERSION}").
  • Original System Version: /bin/bash