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 Type | Recommended 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.
| Flag | Description |
|---|---|
echo 'Text' | Standard output with a line break. |
-n | Disable the trailing line break. |
-e | Enable backslash escapes (e.g., \n for newline). |
Combining Options: You can combine flags like this:
echo -en 'Hello\nWorld'
Navigation: pwd and cd
- Working Directory: The folder where the shell is currently operating.
pwd: Print Working Directory.cd [directory]: Change directory.cd ..: Move to parent directory.cd ~orcd: Move to user home directory.cd /: Move to the system root.
Listing Contents: ls
Syntax: ls [option...] [path]
| Option | Description |
|---|---|
-a | List all entries, including hidden files (starting with .). |
-t | Sort by time (modification time, newest first). |
-r | Reverse order while sorting. |
--color | Enables 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
- Example:
- Relative Paths: Resolved based on current working directory.
- Example:
./Desktopor../Documents
- Example:
Advanced Terminal Tips
- Executing Multiple Commands: Use a semicolon
;.- Example:
echo -n 'Hello '; echo 'World'
- Example:
- Getting Help:
[command] --helpor[command] -hman [command]: Access the built-in manual (e.g.,man ls).
User Management and Privileges
User Categories
Linux users are generally categorized into three types:
- System Accounts:
- Used for running background tasks (webservers, databases).
- Usually do not have a home directory.
- Regular Users:
- Access to their own files/directories only.
- Cannot perform administrative tasks or access other users' files without permission.
- 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
sudocan be destructive.- DO NOT EXECUTE:
sudo rm -rf /etc(this will delete your system configuration).
- DO NOT EXECUTE:
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).
| Command | Description |
|---|---|
sudo apt update | Refreshes the list of available packages (run this first!). |
sudo apt upgrade | Upgrades existing packages and installs required dependencies. |
sudo apt full-upgrade | Large 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 autoremove | Removes 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.
| Command | Description |
|---|---|
sudo dnf update | Fetches package lists and upgrades the system. |
sudo dnf upgrade | Same 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.
- Install Homebrew: Follow instructions at brew.sh.
- Update Homebrew:
brew update - Install Bash:
brew install bash - Upgrade Bash:
brew upgrade bash
Launching Bash
- Latest Version: Type
bashin the terminal (confirm withecho "${BASH_VERSION}"). - Original System Version:
/bin/bash