Post

Linux-M1 - Introduction to Linux

Learn about the basics of Linux. Origins of the Linux operating system and list its key features and use cases. Linux distribution, the names of popular distributions, and their key characteristics. Linux architecture, interact with a Linux system using the terminal, and navigate directories using paths and shortcuts. create and edit text files using text editors such as nano and Vim. Lastly, Use a software package manager to install and updates on a Linux system.

Linux-M1 - Introduction to Linux

Introduction to Linux and Unix


1. What is an Operating System (OS)?

An Operating System (OS) is a software that:

  • Manages computer hardware and system resources such as CPU, memory, disk storage, and input/output devices.
  • Acts as an interface between users and the computer hardware, enabling interaction and allowing users to perform useful tasks.

2. What is Unix?

Definition:

Unix is a family of multitasking, multiuser operating systems originally developed in the 1960s.

Key Characteristics:

  • Designed for servers, workstations, and mainframes.
  • Known for stability, security, and performance.
  • Oracle Solaris
  • FreeBSD
  • HP-UX
  • IBM AIX
  • Apple macOS – one of the most popular desktop operating systems today.

Historical Development of Unix:

  • 1960s: Original Unix OS was developed at AT&T Bell Labs.
    • Initially created for the PDP-7 computer.
  • 1970s: Rewritten in the C programming language, making it portable across different hardware platforms.
  • Late 1970s: Berkeley Software Distribution (BSD) was developed by UC Berkeley.
    • Added new features and tools.
    • Laid the foundation for future systems like macOS.

3. What is Linux?

Definition:

Linux is a family of Unix-like operating systems. When people mention Linux, they usually refer to a specific distribution or flavor of Linux.

Purpose of Linux:

Developed to provide a free, open-source alternative to Unix.

Key Features of Linux:

  • Free and Open Source:
    • Anyone can view, modify, and distribute the source code.
    • Encourages transparency and collaborative development.
  • Security:
    • High security due to open-source nature and community scrutiny.
  • Multi-user:
    • Supports multiple users accessing the system simultaneously.
  • Multitasking:
    • Capable of running multiple applications and jobs at the same time.
  • Portability:
    • Runs on a wide range of hardware platforms — from embedded systems to supercomputers.

4. Historical Development of Linux

1980s: GNU Project

  • Developed at MIT.
  • Stands for “GNU’s Not Unix”.
  • Aimed to create a free, open-source version of Unix system tools.
  • However, lacked a kernel.

1991: Birth of the Linux Kernel

  • Created by Linus Torvalds.
  • Linus announced his project via a famous email, describing his efforts to develop a free, open-source Unix-like kernel.
  • The kernel is the core component of an OS, responsible for communication between software and hardware.

1992: Merging GNU and Linux

  • Developers realized the potential of combining the GNU tools with the Linux kernel, leading to the birth of full-fledged Linux-based operating systems.

1996: Tux the Penguin

  • Created by Larry Ewing, a computer scientist.
  • Adopted by Linus Torvalds as the official Linux mascot.

5. Current Use Cases of Unix and Linux

Unix (e.g., macOS):

  • Widely used on millions of Apple devices worldwide.
  • Based on BSD Unix.

Linux:

  • Powers billions of servers around the world, serving the modern internet.
  • Increasingly popular among developers as a desktop OS (e.g., Ubuntu).

Common Use Cases for Linux Today:

  1. Mobile Devices:
    • Android uses a Linux-based kernel.
    • Billions of smartphones run on Linux-powered Android.
  2. Supercomputing:
    • Used in clusters of high-performance computing systems.
    • Dominates the field of scientific and engineering computation.
  3. Enterprise & Cloud Data Centers:
    • Millions of servers run Linux for hosting web services, databases, and cloud infrastructure.
  4. Personal Computers:
    • Many users install Linux for learning or daily use.
    • Popular distributions include Ubuntu, Fedora, Debian, Linux Mint, etc.

6. Summary

✅ Define what an Operating System (OS) is and its role.
✅ Understand the history and evolution of Unix.
✅ Explain the origins of Linux and how it relates to Unix.
✅ List the key features of Linux: free/open-source, secure, multi-user, multitasking, and portable.
✅ Recognize the modern-day usage of Linux in mobile devices, servers, supercomputers, and PCs.


Overview of Linux Architecture


1. Introduction to Linux System Layers

The Linux system is structured into five distinct layers, each with a specific role in ensuring the smooth operation of the system.

The Five Layers of Linux Architecture:

  1. User Interface (UI)
  2. Application Layer
  3. Operating System (OS) Layer
  4. Kernel Layer
  5. Hardware Layer

2. Layer-by-Layer Breakdown

1. User Interface (UI)

  • Role: Allows users to interact with the system using input devices like keyboard or mouse.
  • Types:
    • Graphical User Interface (GUI) – Found in desktop versions, similar to Windows or macOS.
    • Command Line Interface (CLI) – Used for direct command execution via terminal.

Example: You can use a web browser (application) through the GUI to send an email or a music player to listen to a song.


2. Application Layer

  • Definition: Contains software tools and programs that allow users to perform tasks.
  • Includes:
    • System tools (e.g., compilers)
    • Programming languages
    • Shells (command interpreters like Bash)
    • User applications (web browsers, text editors, games)

These applications communicate with the OS to execute commands and access resources.


3. Operating System (OS) Layer

  • Role: Manages critical system functions to ensure stability and performance.
  • Key Responsibilities:
    • Assigning software access to users
    • Detecting and handling errors
    • Managing files and directories
    • Ensuring system health and resource allocation

This layer sits on top of the kernel and provides high-level management services.


4. Kernel Layer

  • Definition: The core component of the Linux operating system.
  • Function: Acts as a bridge between applications and hardware using system calls.
  • Starts at boot and remains in memory until shutdown.
  • Four Key Functions:
    1. Memory Management – Allocates and manages RAM.
    2. Process Management – Controls running processes and CPU time.
    3. Device Drivers – Enables communication with hardware components.
    4. Security Management – Ensures secure system operations.

The kernel is the lowest-level software in the system and has full control over it.


5. Hardware Layer

  • Definition: Physical or electronic components of the computer.
  • Includes:
    • Central Processing Unit (CPU) – Executes instructions.
    • Random Access Memory (RAM) – Temporary storage during runtime.
    • Storage Devices – Hard drives, SSDs, etc., for persistent data.
    • Input/Output Devices – Keyboard, mouse, screen, USB drives.

The kernel interacts directly with this layer to manage resources and run applications.


3. Linux Filesystem Structure

Overview

  • The Linux filesystem organizes all files and directories in a tree-like structure.
  • The root directory, represented by /, is the topmost level.

Key Directories in the Filesystem

DirectoryPurpose
/ (Root)Top-level directory containing all other directories.
/binEssential user binary files (commands like ls, cp).
/usrUser programs and utilities (e.g., applications).
/homePersonal working directories for users (e.g., /home/user).
/bootFiles needed to boot the system (kernel, bootloader config).
/mediaMount point for removable media (USB drives, CDs).
/etcConfiguration files for system and applications.
/varVariable data such as logs, caches, and spool files.
/tmpTemporary files used by applications and the OS.
/devDevice files representing hardware components.
/libShared libraries required by binaries in /bin and /sbin.

Each file and directory has access rights assigned for security and proper usage.


4. Summary

✅ The five layers of a Linux system: UI, Applications, OS, Kernel, and Hardware.
✅ The role of each layer in enabling user interaction, application execution, and hardware communication.
✅ The structure of the Linux filesystem, including key directories and their purposes.


Visual Representation (Simplified)

1
2
3
4
5
6
7
8
9
[User Interface]
      ↓
[Applications]
      ↓
[Operating System]
      ↓
   [Kernel]
      ↓
   [Hardware]

Quick Recap Table

LayerDescriptionExample
User InterfaceHow users interact with the systemGUI (desktop), CLI (terminal)
Application LayerTools and programs for tasksWeb browser, text editor
Operating SystemManages system health and jobsProcess scheduling, error detection
KernelCore of the OS; communicates with hardwareMemory & process management
HardwarePhysical componentsCPU, RAM, storage, input/output devices

1. Introduction to Text Editors in Linux

Text editors are essential tools for writing, modifying, and managing code or configuration files in a Linux environment.

Two Main Categories of Text Editors:

TypeDescription
Command-line text editorsOperate directly in the terminal. Useful for remote servers and scripting environments.
GUI-based text editorsOffer a graphical interface with menus and toolbars. Ideal for desktop users.

1. GNU nano

  • Description: A beginner-friendly, modeless editor.
  • Features:
    • Undo/Redo
    • Search and Replace (with regex)
    • Syntax highlighting
    • Automatic indentation
    • Line numbers
    • Multiple file buffers

To open or create a file:

1
nano filename.txt

Basic nano Commands (Use Ctrl + [Key])

CommandFunction
Ctrl + GGet Help
Ctrl + WSearch for text (“Where Is”)
Ctrl + OWrite (Save) the file
Ctrl + XExit nano
Ctrl + KCut a line
Ctrl + UPaste a line

2. vi / vim

  • vi: One of the original Unix text editors.
  • vim: Improved version of vi; stands for Vi IMproved.
  • Modes:
    • Insert Mode: For typing/editing text.
    • Command Mode: For navigating, saving, quitting, etc.

To start editing a file:

1
vim filename.txt

Basic vim Workflow

  1. Open file → starts in Command Mode
  2. Press i → switch to Insert Mode
  3. Edit text
  4. Press Esc → return to Command Mode
  5. Save and exit:
    • :w → write/save changes
    • :q → quit
    • :wq → save and quit
    • :q! → quit without saving

Tip: Vim has a steep learning curve but is extremely powerful once mastered.


gedit

  • Default editor in GNOME desktop environments.
  • Designed for simplicity and ease of use.
  • Comes preinstalled on many Linux distributions.

Key Features of gedit:

  • Integrated file browser
  • Undo/Redo functionality
  • Search and Replace (supports regular expressions)
  • Plugin support via gedit-plugins
  • Syntax highlighting for programming languages

Ideal for beginners or anyone who prefers a visual interface.


4. Other Notable Text Editors

emacs

  • One of the oldest open-source projects still maintained.
  • Available in both CLI and GUI modes.
  • Extremely customizable and feature-rich.
  • Often used by developers for complex coding tasks.

5. Summary of Key Concepts

List popular Linux text editors, both command-line and GUI-based.
Describe features of gedit, the default GUI editor in GNOME.
Open and edit files using nano and vim from the command line.
Understand basic commands for navigating and saving files in nano and vim.


Quick Reference Table

EditorTypeStrengthsCommon Use Case
nanoCLISimple, easy to useQuick edits, beginner-friendly
vimCLIPowerful, fast, modalAdvanced editing, scripting
geditGUIUser-friendly, syntax highlightingDesktop development, casual editing
emacsCLI/GUIHighly extensible, customizableDevelopment, long-term projects

Linux Distributions


1. What is a Linux Distribution (Distro)?

A Linux distribution, or distro, is a specific version or “flavor” of the Linux operating system.

Key Components of a Linux Distro:

  • Must include the Linux kernel – the core component that communicates with hardware.
  • Includes a set of default utilities and applications.
  • Comes with a Graphical User Interface (GUI) for user interaction.
  • Supports various shell commands for terminal-based operations.
  • Offers different support models:
    • Community-backed or enterprise-supported.
    • May be a Long-Term Support (LTS) release or follow a rolling release model.

There are hundreds of Linux distros, each tailored for specific audiences or tasks like servers, desktops, embedded systems, or educational purposes.


2. What Differentiates Linux Distributions?

Linux distributions differ in several key ways:

FeatureDescription
Default Applications & UtilitiesEach distro comes with its own set of pre-installed software tools.
Graphical User Interface (GUI)Some use GNOME, KDE, XFCE, or other desktop environments.
Shell Commands & ToolsMay vary slightly depending on the distro’s configuration and package manager.
Support ModelCommunity-driven (e.g., Debian) or enterprise-backed (e.g., Red Hat).
Release Cycle<ul><li>LTS (long-term support): stable updates over years.</li><li>Rolling release: continuous updates with latest software versions.</li></ul>

1. Debian

  • First Release: 1993 (version 0.01), first stable release in 1996 (v1.1).
  • Features:
    • Stable, reliable, and fully open source.
    • Supports many hardware architectures.
    • Maintained by a community-run project.
  • Use Case:
    • Widely used in server environments due to its stability.
    • Foundation for many other distros like Ubuntu.

2. Ubuntu

  • First Official Release: 2004.
  • Base: Based on Debian.
  • Developer: Maintained by Canonical Ltd.
  • Editions:
    • Ubuntu Desktop: For personal computers and workstations.
    • Ubuntu Server: For file servers and cloud infrastructure.
    • Ubuntu Core: Designed for IoT devices.
  • Use Case:
    • Popular among beginners and developers.
    • Used in cloud computing and enterprise environments.

3. Red Hat Enterprise Linux (RHEL)

  • Developer: Maintained by Red Hat (an IBM subsidiary).
  • Features:
    • Commercial-grade OS focused on enterprise customers.
    • Fully open source but requires subscription for official support.
  • Use Case:
    • Commonly used in large enterprises, data centers, and mission-critical applications.

4. Fedora

  • Developer: Sponsored by Red Hat.
  • Relation to RHEL: Code from Fedora is often incorporated into RHEL after testing.
  • Features:
    • Stable and secure with advanced firewall features.
    • Actively developed with a growing community.
  • Use Case:
    • Favored by developers and contributors who want cutting-edge features before they appear in RHEL.

5. SUSE Linux Enterprise (SLE)

  • Developer: Maintained by SUSE, a German open-source company.
  • Editions:
    • SLES (Server Edition): For enterprise servers.
    • SLED (Desktop Edition): For enterprise desktop users.
  • Features:
    • Supports multiple architectures including ARM (e.g., Raspberry Pi).
    • Uses SUSE Package Hub for extended software packages.
  • Use Case:
    • Common in enterprise environments, especially in Europe and Asia.

6. Arch Linux

  • Features:
    • Do-it-yourself approach – minimal base system that users customize.
    • Highly configurable and lightweight.
    • Follows a rolling release model – always up-to-date with latest software.
  • Learning Curve:
    • Requires strong knowledge of Linux internals.
  • Use Case:
    • Popular among advanced users and enthusiasts who prefer full control over their system.

4. Summary

What a Linux distribution is and what components it includes.
✅ The differences between Linux distros based on GUI, tools, support, and release cycles.
✅ The unique features and use cases of popular distros such as Debian, Ubuntu, Red Hat, Fedora, SUSE, and Arch Linux.


Quick Comparison Table

DistroTypeUse CaseSupportRelease Model
DebianCommunityServersFreeStable releases
UbuntuCommercialDesktop, CloudCanonicalLTS & Regular
RHELEnterpriseEnterprise ServersPaidStable releases
FedoraCommunityDevelopmentRed HatRolling updates
SUSEEnterpriseEnterprise SystemsSUSEStable releases
ArchCommunityCustomizationCommunityRolling release

Linux Terminal Overview


1. What is the Linux Shell?

Definition:

The Linux shell is an OS-level application that interprets and executes commands entered by a user.

Key Points:

  • In early Unix/Linux systems, the shell was the only interface available.
  • Today, GUIs exist, but the shell remains a powerful and flexible tool.
  • It allows users to:
    • Run programs
    • Manipulate files (copy, move, delete)
    • Read/write data
    • Search and filter content
  • Can also be used for scripting, automating repetitive tasks.
  • Bash (Bourne Again SHell) – Most widely used.
  • Zsh (Z Shell) – More modern features and customization.

2. What is the Linux Terminal?

Definition:

A terminal is an application or interface where you type commands and view their output.

How It Works:

  • You enter commands in the terminal.
  • The terminal sends them to the shell for execution.
  • The shell communicates with the OS and hardware.
  • Results are returned to the terminal for display.

Example:

1
python myprogram.py

This runs a Python script called myprogram.py and displays its output (e.g., “Hello, World!”).


3. How Terminal and Shell Work Together

Step-by-Step Execution Flow:

  1. User types a command in the terminal.
  2. Terminal sends the command to the shell.
  3. Shell interprets the command and communicates with the operating system and kernel.
  4. Kernel interacts with hardware to execute the task.
  5. Once completed, results are passed back through the chain to the terminal, where they are displayed to the user.

4. Understanding the Command Line Interface (CLI)

Command Prompt:

  • The blinking cursor where you type your commands.
  • Often shows the current working directory.
  • Example prompt:
    1
    
    /home/me/Documents $
    

Current Working Directory:

  • This is the directory where the shell will look for files or run commands.
  • You can change it using the cd command.

5. Navigating the Filesystem Using the Terminal

Basic Commands for Navigation:

CommandDescription
cd /Move to the root directory (/)
cd binMove into the bin directory from current location
cd ~Go to the user’s home directory
cd ..Move up one level to the parent directory
cd ../..Move up two levels in the directory tree
cd /home/me/DocumentsNavigate directly to a specific path

6. Understanding Paths in Linux

Path:

A human-readable location of a file or directory in the filesystem.

Types of Path Notation:

SymbolMeaningExample
/Root directory/home/user/file.txt
~User’s home directory~/Documents
.Current directory./file.txt
..Parent directory../other_folder

Path structure uses forward slashes:
Example: a/b means “b” is inside “a”.


7. Listing Files and Running Programs

List Files in Current Directory:

1
ls
  • Displays all files and directories in the current folder.

Run an Executable File:

1
./ls
  • Runs the ls program located in the current directory.

Note: Many commands like ls are built into the shell and don’t require ./.


8. Practical Examples

Example 1: Navigating to the Home Directory

1
cd ~

Even if ls isn’t in the current directory, you can still use it because it’s part of the system PATH.

Example 2: Moving Up and Down the Filesystem

1
cd ../..

Moves up two levels in the directory hierarchy.

1
cd /home/me/Documents

Navigates directly to the Documents folder.

Example 3: Running a Python Script

1
2
cd /home/me
python myprogram.py

Runs a Python script named myprogram.py located in the current directory.


9. Summary

✅ What the Linux shell is and how it interprets commands.
✅ What a terminal is and how it serves as the interface for interacting with the shell.
✅ How the terminal and shell work together to execute commands via the kernel and hardware.
✅ How to navigate directories using the cd command and understand path structures in Linux.


Quick Reference Table

TaskCommand
Change to root directorycd /
Go to home directorycd ~
Move to parent directorycd ..
Move to specific pathcd /home/me/Documents
List contents of current directoryls
Run a Python scriptpython myprogram.py

Browsing Directories with the Linux Terminal


Learning Objectives

By the end of this guide, you will be able to:

✅ Understand what a Linux terminal is and how it works
✅ Use the pwd command to display your current working directory
✅ Use the ls command to list contents of a directory


1. What Is the Linux Terminal?

The Linux terminal, also known as:

  • Command line
  • Shell prompt
  • Command prompt

It is a text-based interface used to interact with the operating system by typing commands.

Understanding the Prompt

You may see something like:

1
/home/project $
  • /home/project – This is the current working directory
  • $ – The command prompt, where you type commands

On some systems, you might see # instead of $. A # indicates you’re logged in as a superuser (root).


2. pwd – Print Working Directory

Purpose

Shows the full path of the directory you are currently in.

Usage

1
pwd

Example Output

1
/home/project

This means you are in the project subdirectory inside the home directory.


3. ls – List Directory Contents

Purpose

Displays files and directories in the current location or specified location.

Basic Usage

1
ls

If the current directory is empty, the command returns no output — not even a blank line.

List Contents of a Specific Directory

You can specify a directory path:

1
ls /home

Example Output

1
project  theia

This shows that the /home directory contains two subdirectories: project and theia.


4. Understanding Filesystem Paths

Linux uses a tree-like structure for organizing files and directories.

Root Directory

  • Represented by / (called “slash”)
  • The topmost directory in the filesystem

Subdirectories

  • Folders within other folders
  • Example: /home/project means:
    • project is a subdirectory inside home
    • home is a subdirectory inside the root (/)

Path Examples

PathDescription
/Root directory
/homeHome directory (contains user directories)
/home/projectUser-specific directory for projects

5. Summary of Commands

CommandDescriptionExample
pwdPrint Working Directory – show current locationpwd/home/project
lsList contents of current directoryls
ls <dir>List contents of a specific directoryls /home

6. Final Notes

  • The terminal allows you to interact with your Linux system using text commands.
  • Use pwd to always know where you are in the file system.
  • Use ls to explore what’s inside a directory.
  • You can navigate through the Linux file system using paths and commands like cd, which you’ll learn more about in future lessons.

Linux Terminal Tips: Tab Completion & Command History


Learning Objectives

By the end of this guide, you will be able to:

✅ Use Tab Completion to speed up command typing
✅ Use Command History to reuse or edit previous commands

These two features help make working in the Linux terminal faster, more efficient, and less error-prone.


1. Tab Completion – Speed Up Typing Commands

What is Tab Completion?

A time-saving feature that auto-fills partially typed commands, file names, or paths when you press the Tab key.

Works for:

  • Commands
  • File names
  • Directory paths

How It Works

  • Type part of a name and press Tab
  • The shell tries to complete it automatically
  • If multiple matches exist, pressing Tab again may show suggestions or do nothing until more characters are entered

Examples

Example 1: Navigate to Pictures

1
cd P<TAB>

Becomes:

1
cd Pictures/

Because Pictures is the only directory starting with “P”.

Example 2: Ambiguous Match (Do → Documents vs Downloads)

1
cd Do<TAB>

No auto-complete because both Documents and Downloads start with “Do”.

Example 3: Specific Match (Doc → Documents)

1
cd Doc<TAB>

Becomes:

1
cd Documents/

Only one match found.

Example 4: Long Path Completion

Inside ~/Documents:

1
cd py<TAB>

If there’s only one folder named python-examples, it becomes:

1
cd python-examples/

You can keep pressing Tab to go deeper into nested directories if they’re unambiguous.


2. Command History – Reuse Previous Commands

What is Command History?

Linux keeps a record of all commands you’ve entered during your session.

You can navigate this list using:

  • ↑ (Up Arrow) – Go back through older commands
  • ↓ (Down Arrow) – Move forward toward newer commands

This lets you reuse or modify previous commands without retyping them.

How to Use It

Scenario: You ran these commands

1
2
3
cd ~/Documents/python-examples
python3 myprogram.py
cd /

Now, at the prompt:

1
/ $

Step 1: Press ↑ once

Repeats the last command:

1
cd /

Step 2: Press ↑ again

Repeats:

1
python3 myprogram.py

Step 3: Press ↑ again

Repeats:

1
cd ~/Documents/python-examples

Tip: If you go too far back, use the ↓ arrow to move forward through history.


3. Summary Table

FeatureDescriptionExample
Tab CompletionAuto-completes commands, filenames, or pathsType cd Doc<TAB> → completes to cd Documents/
Command HistoryRecalls previously used commandsUse ↑ and ↓ arrows to scroll through commands

4. Final Tips

  • Use Tab Completion to avoid typos and save time.
  • Use Command History to repeat or tweak earlier actions.
  • Combine both features to work faster and smarter in the terminal.

Exercise 1 - Browsing Directories with ls

In this exercise, you’re learning how to navigate and view the contents of directories using the ls command in a Linux shell environment.


📌 Summary of Key Concepts

🔹 What is ls?

  • ls is a command used to list directory contents.
  • It is actually a program located at /bin/ls.
  • When you type ls, the shell runs /bin/ls to show files and folders in the current or specified directory.

1.1 Viewing Files in the Current Working Directory

Command:

1
ls

Explanation:

  • This lists all files and directories in your current working directory.
  • In this lab environment, your current directory is /home/project.
  • Since it’s empty, running ls returns nothing (no output).

1.2 Viewing Files in Any Directory

You can list the contents of any directory by specifying its path:

Command:

1
ls [PATH TO DIRECTORY]

Example:

1
ls /
  • Lists the contents of the root directory (/).

Common System Directories:

DirectoryContents
/binEssential user command binaries (like ls, cp, mv)
/sbinSystem administration binaries
/usrUser programs and data
/homeHome directories for users
/mediaMount points for removable media

🧪 Try These Commands

To explore the system, try these in your terminal:

1
2
3
4
5
ls /              # List root directory contents
ls /bin           # List commands available in /bin
ls /home          # See what users exist (you may see 'project')
ls /etc           # Configuration files
ls /usr/bin       # More user-level command binaries

💡 Tip

  • If you want to see hidden files (those starting with a dot), use:

    1
    
    ls -a
    
  • To get a detailed list (including file permissions, size, owner, etc.):

    1
    
    ls -l
    

Exercise 2 - Navigating Directories with cd

In this exercise, you’re learning how to change directories using the cd (change directory) command in a Linux shell.


🧭 Key Navigation Symbols

SymbolMeaningExample
~Your home directorycd ~ goes to /home/theia
/The root directory of the systemcd /
.The current directorycd . stays where you are
..The parent directorycd .. moves up one level

2.1 Changing to Your Home Directory

1
cd ~
  • This takes you to your default home directory, which is typically /home/theia in this lab environment.
  • To confirm:
    1
    
    pwd
    

2.2 Going to the Parent Directory

1
cd ..
  • Moves up one level in the directory hierarchy.
  • Example: If you’re in /home/theia, this will take you to /home.

2.3 Changing to the Root Directory

1
cd /
  • Takes you to the top-level directory of the file system, called the root directory.

2.4 Changing to a Child Directory

Method 1: Relative Path

1
cd bin
  • From /, this will go to /bin.
  • Assumes bin is a subdirectory of your current working directory.

Method 2: Using . (Current Directory)

1
cd ./bin
  • Also changes to /bin if you’re currently in /.

⚠️ Tip: Make sure you’re in the correct parent directory before navigating into a child directory. If you’re already in /bin, typing cd ./bin would try to go to /bin/bin, which may not exist.


2.5 Returning to Your Home Directory

Option 1: Using ~ (Fastest Way)

1
cd ~
  • Directly returns you to /home/theia.

Option 2: Using Relative Path

1
cd ../home/theia
  • Goes up to /home, then into the theia folder.

2.6 Navigating to the Project Directory

1
cd ../project
  • This switches you from /home/theia to its sibling directory: /home/project.
  • Useful for moving between related folders inside /home.

📌 Final Tips

  • Use pwd (Print Working Directory) often to see where you are:
    1
    
    pwd
    
  • Combine paths using slashes:
    1
    
    cd /home/project/myfolder
    
  • Tab completion helps! Start typing a directory name and press Tab to auto-complete.

Exercise 3 - Using Tab Completion and Command History

In this exercise, you learned two powerful tools to make working in the terminal faster, easier, and less error-prone:

  • 🔁 Command history
  • Tab completion

🔄 3.1 Scrolling Through Command History

You can easily review and reuse previously entered commands using:

KeyAction
(Up Arrow)Go back one command
(Down Arrow)Go forward one command

Example:

If you previously typed:

1
2
3
cd /
cd bin
ls

Then pressing will bring back ls, then cd bin, then cd /, etc.

Use Case:

Let’s say you want to run cd bin again:

  • Instead of retyping it, press until you see cd bin
  • Press Enter to execute it again

💡 If the command doesn’t work because your current directory changed, keep scrolling until you find cd /, run that first, then try cd bin.


🧠 3.2 Using Tab Completion

Tab completion helps you type faster by auto-filling file and directory names.

How It Works:

Step-by-step example:

  1. Type:
    1
    
    cd /bi
    
  2. Press Tab
    • It autocompletes to:
      1
      
      cd /bin
      

What if there are multiple matches?

Try typing:

1
cd /b

Then press Tab once → nothing happens
Press Tab twice → You’ll see options like:

1
bin/   boot/

Now add an i:

1
cd /bi

Press Tab again → completes to:

1
cd /bin

Tip:

  • Double-tab (Tab + Tab) shows all possible completions.
  • Only works when there’s one match or you’re asking for help with ambiguous paths.

🛠️ Practice: Digging Into a Path Using Tab Completion

Let’s build a longer command using tab completion:

Start typing:

1
ls /ho

Press Tab → becomes:

1
ls /home/

Now type:

1
ls /home/the

Press Tab → becomes:

1
ls /home/theia

Keep going:

1
ls /home/theia/dsdriver/bi

Press Tab → becomes:

1
ls /home/theia/dsdriver/bin

This way, you built:

1
ls /home/theia/dsdriver/bin

…without typing the whole thing!


✅ Summary of Tips

FeatureShortcutDescription
Command History / Scroll through previous commands
Tab CompletionTabAuto-complete file/directory names
Show OptionsTab + TabList possible completions
Speed & AccuracyMix of bothAvoid typos and save time

Linux Packages and Package Managers


1. What Are Packages in Linux?

A package is a file that contains:

  • The software application or update
  • Metadata (version, dependencies, etc.)
  • Installation scripts

Packages are used to install, update, or remove software on Linux systems.

Common package formats:

  • .deb – for Debian-based distributions
  • .rpm – for Red Hat-based distributions

2. Understanding Package Managers

What Is a Package Manager?

A tool that automates the process of:

  • Downloading packages from repositories
  • Installing, updating, configuring, and removing software
  • Resolving dependencies automatically

Types of Package Managers:

TypeDescriptionExamples
GUI-basedVisual interface for managing softwareUpdate Manager, PackageKit
CLI-basedTerminal-based toolsapt, yum, dnf

3. Differences Between .deb and .rpm Packages

Feature.deb.rpm
Used byDebian, Ubuntu, Linux MintCentOS, RHEL, Fedora, openSUSE
Package managerapt, dpkgyum, dnf, rpm
File extension.deb.rpm
Conversion possible?Yes, using the alien tool 

Example: Convert an RPM to DEB format:

1
sudo alien package.rpm

Convert a DEB to RPM format:

1
sudo alien -r package.deb

4. GUI-Based Package Managers

Update Manager (Debian/Ubuntu)

  • Default GUI tool for .deb systems.
  • Automatically checks for updates daily.
  • Installs security updates automatically.
  • Allows manual update checking and selection of specific updates.

PackageKit / Software Update (RPM-based Systems)

  • Default GUI tool for .rpm systems like Fedora or CentOS.
  • Shows a notification icon when updates are available.
  • Lets you select and install updates with password authentication.

5. Command-Line Package Managers

For Debian/Ubuntu (.deb): apt

APT stands for Advanced Package Tool.

Common Commands:

TaskCommand
Update package listsudo apt update
Upgrade all packagessudo apt upgrade
Install a specific packagesudo apt install package_name
Remove a packagesudo apt remove package_name
Search for a packageapt search keyword

For Red Hat/CentOS/Fedora (.rpm): yum / dnf

  • yum: Older but widely used on CentOS/RHEL 7
  • dnf: Newer version used in Fedora and RHEL 8+

Common Commands (yum/dnf):

TaskCommand
Update all packagessudo yum update or sudo dnf upgrade
Install a packagesudo yum install package_name or sudo dnf install package_name
Remove a packagesudo yum remove package_name or sudo dnf remove package_name
Search for a packageyum search keyword or dnf search keyword

6. Using Package Managers to Install Software

You can use package managers not only for system-level applications but also for programming languages and development tools.

Example: Installing Python Libraries via pip

1
pip install pandas

This command:

  • Searches for the latest version of pandas
  • Downloads and installs it
  • Installs any required dependencies

Similar tools exist:

  • conda – for data science environments
  • npm – for JavaScript/Node.js
  • gem – for Ruby

7. Summary

Define what a Linux package is and how it’s used.
Differentiate between .deb and .rpm package formats and understand how they can be converted.
Use GUI-based package managers like Update Manager and PackageKit to check and install updates.
Use CLI tools like apt and yum to manage software on your system.
Install new software using package managers for both system and development purposes.


Quick Reference Table

TaskDebian/Ubuntu (.deb)Red Hat/CentOS/Fedora (.rpm)
GUI ToolUpdate ManagerPackageKit
CLI Toolaptyum / dnf
Update Systemsudo apt update && sudo apt upgradesudo yum update
Install Packagesudo apt install package_namesudo yum install package_name
Remove Packagesudo apt remove package_namesudo yum remove package_name
Search Packageapt search keywordyum search keyword

Exercise 1 - Upgrading and Installing Packages with apt

In this exercise, you learned how to use the sudo command along with apt, a powerful package management tool in Linux. You used it to:

  • Update your system’s package list
  • Upgrade an existing package (nano)
  • Install a new package (vim)

🔐 1.1 Updating Your System’s Package List Index

Command:

1
sudo apt update

What It Does:

  • Fetches the latest list of available packages and their versions from configured repositories.
  • Ensures that your system knows about the most recent software updates and dependencies.

🕒 This command may take a few moments to complete.
💡 You can view the repository sources at /etc/apt/sources.list.


✏️ 1.2 Upgrading nano

Command:

1
sudo apt upgrade nano

What Happens:

  • Upgrades the already installed nano text editor to the latest version.
  • You’ll be prompted:
    1
    
    Do you want to continue? [Y/n]
    
  • Press Y then Enter to proceed.

⚠️ If you see a : prompt during the process (like in a pager), press q to quit and continue.


💾 1.3 Installing vim

Command:

1
sudo apt install vim

Why Vim?

  • Vim is a highly configurable, powerful text editor.
  • Ideal for editing files directly in the terminal.
  • Widely used by developers and system administrators.

Installation Steps:

  1. Run:
    1
    
    sudo apt install vim
    
  2. Confirm with:
    1
    
    Do you want to continue? [Y/n]
    

    Type Y and press Enter

🧠 Note: Always run sudo apt update before installing or upgrading packages to ensure you’re getting the latest software versions.


📌 Summary Table

TaskCommand
Update package listsudo apt update
Upgrade a package (e.g., nano)sudo apt upgrade nano
Install a new package (e.g., vim)sudo apt install vim

🧪 Quick Tips

  • To check if a package is installed:
    1
    
    which nano
    
  • To view the version of a program:
    1
    2
    
    nano --version
    vim --version
    

Exercise 2 - Creating and Editing Files with nano

In this exercise, you learned how to create and edit files using the nano text editor from the command line.


🧭 2.1 Navigating to Your Project Directory

Command:

1
cd /home/project

Tip: Use Tab Completion

You can type:

1
cd /home/pr

Then press Tab, and it will auto-complete to:

1
cd /home/project

Once there, verify with:

1
ls
  • This shows the contents of your directory.
  • Since it’s empty at first, you won’t see anything yet.

✏️ 2.2 Creating and Editing a File with nano

Create a new file:

1
nano hello_world.txt

This opens the nano editor and creates the file.

Inside Nano:

  1. Type:
    1
    
    Hello world!
    
  2. Press Enter
  3. Type:
    1
    
    This is the second line of my first-ever text file created with nano.
    

Save and Exit:

  • Press CTRL + X to exit
  • You’ll be prompted:
    1
    
    Save modified buffer?  Y Yes   N No   ^C Cancel
    
  • Press Y to save
  • Confirm the filename by pressing Enter

Nano saves the file and returns you to the terminal.


🔍 2.3 Verifying Your File Content

To view the contents of your file:

1
cat hello_world.txt

You should see:

1
2
Hello world!
This is the second line of my first-ever text file created with nano.

✅ Success! You’ve just created and edited your first file in Linux using nano.


📋 Summary of Commands

ActionCommand
Navigate to project directorycd /home/project
Create/edit a file with nanonano hello_world.txt
Save and exit in nanoCTRL + X, then Y, then Enter
View file contentscat hello_world.txt

🧠 Pro Tip:
If you ever get stuck inside nano, remember:

  • Use arrow keys to navigate
  • Look at the bottom of the screen for shortcut hints like ^X (CTRL+X)

Exercise 3 - Creating and Editing Files with Vim

In this exercise, you learned how to use Vim, a powerful and highly configurable text editor that is widely used in Linux environments. Vim uses different modes for editing and executing commands.


🧭 3.1 Quick Intro to Vim

Launching Vim

To start Vim:

1
vim

You’ll see something like:

1
2
3
4
VIM - Vi IMproved
...
:type :q<Enter> to exit
:type :help<Enter> for on-line help

Basic Commands

ModeActionCommand
Normal (Command) ModeOpen help:help
Normal ModeQuit Vim:q
Any ModeForce quit without saving:q!
Normal ModeSave file:w
Normal ModeSave and quit:wq

Try It:

  • Enter :help to explore the built-in documentation.
  • Press Esc to make sure you’re in Normal Mode.
  • Type :q to exit help or :q! to exit Vim without saving changes.

💡 Tip: If you ever get stuck in Vim, press Esc, then type :q! to safely exit without saving.


✏️ 32.2 Creating and Editing a Text File with Vim

Step-by-step Instructions:

1. Navigate to your project directory:

1
cd /home/project

Use tab completion if possible:

1
cd /home/pr<TAB>

2. Create and open a new file:

1
vim hello_world_2.txt

This opens a new blank file in Normal Mode.

3. Switch to Insert Mode:

Press:

1
i

Now you can type into the file.

4. Add content:

Type:

1
Hello World!

Press Enter to go to the next line, then type:

1
This is the second line.

5. Exit Insert Mode:

Press:

1
Esc

You’re now back in Normal Mode.

6. Save the file:

Type:

1
:w

This writes (saves) the contents of the buffer to the file.

7. Quit Vim:

Type:

1
:q

You’ll return to the command prompt.


🔍 Verify Your File Was Saved

Use the cat command to view the contents:

1
cat hello_world_2.txt

You should see:

1
2
Hello World!
This is the second line.

✅ Congratulations! You’ve created and edited a file using Vim.


📋 Summary of Key Commands in Vim

TaskCommand
Start Vimvim filename.txt
Enter Insert Modei
Exit Insert ModeEsc
Save file:w
Save and quit:wq
Quit without saving:q!
Get help:help
Quit help:q

🧠 Pro Tips:

  • Always press Esc before typing : to ensure you’re in Normal Mode.
  • Vim has many modes: Normal, Insert, Visual, and more — we only covered the basics here.
  • To learn more about Vim, visit https://www.vim.org, where you’ll find tutorials, plugins, and tips from the community.

🎉 Summary: Great Job Completing the Lab!

You’ve just taken a big step in mastering essential Linux skills. Here’s what you accomplished:


🔧 System Administration Skills

You learned how to manage software on your system using apt and sudo:

  • ✅ Updated package list:
    1
    
    sudo apt update
    
  • ✅ Upgraded an existing package (nano):
    1
    
    sudo apt upgrade nano
    
  • ✅ Installed a new package (vim):
    1
    
    sudo apt install vim
    

These are foundational skills for maintaining and customizing any Linux environment.


📝 Text Editing with Nano and Vim

You created and edited files using two powerful command-line editors:

  • ✏️ Nano – beginner-friendly, great for quick edits
    • Created and saved hello_world.txt
    • Viewed content using cat hello_world.txt
  • 💻 Vim – powerful and efficient once you learn the modes
    • Created and saved hello_world_2.txt
    • Practiced switching between Insert Mode and Command Mode

This gives you flexibility depending on your use case or preference!


🖥️ Bash Shell Proficiency

Throughout this lab, you became more comfortable with:

  • 🧭 Navigating directories using cd, pwd, and tab completion
  • 📁 Listing contents of directories using ls
  • ⏳ Reusing commands via the command history ( / )
  • 🚀 Saving time with tab auto-completion
  • 💾 Viewing file contents with cat

These skills will help you become fluent in the terminal — the heart of Linux system administration and development.


🌱 What’s Next?

Here are some great next steps to continue building your Linux expertise:

🔍 File Management:

  • Learn how to copy, move, and delete files with cp, mv, and rm
  • Explore directory trees using tree (install it if needed!)

🛠️ Advanced Vim:

  • Practice more Vim navigation and editing shortcuts
  • Try out visual mode, search/replace, and macros

📊 File Comparison:

  • Use diff to compare files
  • Try less, head, and tail to view large files

🧪 Scripting:

  • Start writing your first Bash script using nano or vim
  • Make it executable with chmod +x myscript.sh

🙌 Final Words

You’re well on your way to becoming confident and proficient in Linux. The more you explore, experiment, and practice, the more natural these tools will feel.

Remember: The terminal is not scary — it’s powerful. And now, it’s yours to master.

📄 Module 1 Cheat Sheet – Introduction to Linux

This cheat sheet summarizes the essential commands and concepts covered in this module. Keep it handy for quick reference while working in the Linux terminal.


🔧 Linux Terminal Tips

TaskCommand
Autocomplete path or commandTab key
Scroll through command history / arrow keys

Getting Information

TaskCommand
View manual for a command (e.g., ls)man ls

🗂️ Browsing and Navigating Directories

🧭 Special Path Symbols

SymbolMeaning
~Your home directory
/Root directory
.Current directory
..Parent directory

📁 Directory Commands

TaskCommand
List contents of current directoryls
List contents of another directoryls path_to_directory
Show current working directorypwd
Change to a subdirectorycd child_directory_name
Move up one directory levelcd ../
Go to your home directorycd ~ or just cd
Go to root directorycd /
Switch to a sibling directorycd ../sibling_dir_name
Return to previous working directorycd -

📦 Upgrading and Installing Packages

Use sudo to run administrative commands.

TaskCommand
Update package listsudo apt update
Upgrade an existing package (e.g., nano)sudo apt upgrade nano
Install a new package (e.g., vim)sudo apt install vim

✏️ Creating and Editing Files

TaskCommand
Create or edit a file with nanonano file_name.txt
Create or edit a file with vimvim file_name.txt

💻 Vim Modes Reminder

  • Normal Mode: Press Esc – use for navigation and commands
  • Insert Mode: Press i – use for typing/editing text

Common Vim Commands (in Normal Mode):

ActionCommand
Save (write) file:w
Quit:q
Save and quit:wq
Quit without saving:q!
Get help:help

🎉 Summary & Highlights – Module Complete!

Great job completing this module! You’ve built a solid foundation in Linux fundamentals, from its history to core components and practical tools. Here’s a concise recap of what you’ve learned:


🕰️ A Brief History of Linux

  • GNU Project (1980s):
    Developed at MIT as a free, open-source alternative to Unix — meaning “GNU’s Not Unix”.
  • Linux Kernel (1991):
    Created by Linus Torvalds — a free, open-source Unix-like kernel that became the heart of modern Linux OS.

💻 Where Is Linux Used Today?

Linux powers:

  • 📱 Mobile devices (e.g., Android)
  • 🖥️ Desktop computers
  • 🌐 Servers (including most web servers)
  • 🚀 Supercomputers
  • ☁️ Cloud infrastructure

Its flexibility and stability make it ideal for both personal and enterprise environments.


🧩 Linux Distributions (Distros)

Different flavors of Linux tailored to specific needs:

DistributionUse Case
UbuntuBeginner-friendly, desktop and server
DebianStable, community-driven
FedoraCutting-edge features, developer-focused
Red Hat Enterprise Linux (RHEL)Enterprise use, commercial support
SUSE (SLES/SLED/OpenSUSE)Enterprise and development
Linux MintEasy for Windows users to switch
ArchDIY-oriented, rolling release model

Each distro varies in:

  • User interface (UI)
  • Package management
  • Support structure
  • Target audience

🏗️ The Five Layers of Linux Architecture

  1. User Interface (UI): Where users interact with applications.
  2. Applications: Programs used to perform tasks (e.g., browsers, editors).
  3. Operating System: Manages system resources and ensures smooth operation.
  4. Kernel: The core of Linux; handles communication between software and hardware.
  5. Hardware: Physical components like CPU, memory, disk drives.

Everything runs on top of the kernel, which is the bridge between your apps and your computer’s physical components.


📁 Filesystem Overview

  • Linux uses a tree-like hierarchical filesystem.
  • Starts from the root directory (/).
  • Common directories:
    • /bin – essential commands
    • /etc – configuration files
    • /home – user directories
    • /usr – user programs
    • /var – variable data (logs, caches)

🖥️ Shell and Terminal Basics

  • A shell is a command-line interpreter (e.g., Bash).
  • You interact with the shell via a terminal emulator.
  • Key navigation commands:
    • cd – change directory
    • ls – list contents
    • pwd – show current path
    • man – view manual pages

✍️ Text Editors in Linux

You can edit files using:

  • 🖋️ Command-line editors:
    • nano – beginner-friendly
    • vim / vi – powerful but has a learning curve
  • 🖼️ GUI-based editors:
    • gedit
    • Kate
    • VS Code (available on Linux)

📦 Package Management

Two major package formats:

  • .deb – used by Debian, Ubuntu, and derivatives
  • .rpm – used by Red Hat, Fedora, SUSE, and others

Common package managers:

  • APT (Advanced Packaging Tool) – used in Debian/Ubuntu
  • YUM/DNF – used in RHEL/Fedora

Basic commands:

1
2
3
sudo apt update       # Update package list
sudo apt upgrade      # Upgrade packages
sudo apt install      # Install new packages

🧠 Final Thoughts

You now understand:

  • The origins and evolution of Linux
  • How Linux powers today’s digital world
  • The structure of a Linux system
  • How to navigate the terminal
  • How to manage packages and edit files

This sets the stage for deeper exploration into scripting, permissions, networking, containers, and more!


📘 Ready for the Next Module?
Let me know if you’d like to dive into:

  • Shell scripting
  • File permissions
  • Process management
  • Networking basics
    Or any other topic you’re curious about!

Keep up the awesome work — Linux mastery is within your reach! 🐧🚀


This post is licensed under CC BY 4.0 by the author.