Linux Learning Resources - Practical Guides

Comprehensive practical guides for learning Alpine Linux system administration, file management, networking, and user management.

Table of Contents

  1. Essential Concepts
  2. File System Basics
  3. File Permissions
  4. User & Group Management
  5. Basic Commands Reference
  6. Networking Basics

Essential Concepts

What is the Linux File System?

Unlike Windows, Linux uses a single, unified directory tree starting from / (the root). Everything in Linux starts from the ‘root’ directory represented by a single forward slash. All other directories are branches off this root.


File System Basics

The Linux File System Hierarchy (FHS)

Here are the most important top-level directories:

Directory Name Purpose
/ Root The top of the entire file system tree
/bin Binary Essential user command binaries (ls, cp, mv, rm)
/sbin System Binaries System administration binaries (reboot, fdisk)
/etc Etcetera Configuration files (network, user configs)
/home Home User home directories (personal files & settings)
/usr Unix System Resources User programs & utilities (/usr/bin, /usr/local)
/var Variable Variable data files (logs, mail, temporary files)
/tmp Temporary Temporary files (often deleted after reboot)
/dev Devices Device files (hard drives, USB devices, terminals)
/proc Processes Process info pseudo-filesystem (kernel parameters)
/opt Optional Optional add-on application software packages

Paths: Absolute vs. Relative

A ‘path’ is the address of a file or directory in the file system.

Absolute Path: - Starts with a / (the root directory) - Provides the complete location from the top of the file system - You can use it from any current directory - Example: /home/user/documents/report.txt

Relative Path: - Does NOT start with a / - Specifies a location relative to your current working directory (pwd) - Uses special symbols: - . (single dot): Current directory - .. (double dot): Parent directory (one level up) - Example (if in /home/user): - documents/report.txt → refers to /home/user/documents/report.txt - ../another_user/public.txt → refers to /home/another_user/public.txt - ./my_script.sh → refers to my_script.sh in current directory

File Types

In Linux, “everything is a file” – but there are different types of files:

Type Symbol Description
Regular File - Documents, images, programs
Directory d Contains other files and directories
Symbolic Link l Pointer or shortcut to another file
Character Device c Hardware device (like serial ports)
Block Device b Hardware device (like hard drives)

File Permissions

The Three Permission Types (rwx)

For every file and directory, there are three basic types of permissions:

r (read): - On a file: Allows viewing the content of the file - On a directory: Allows listing the contents (using ‘ls’)

w (write): - On a file: Allows modifying or deleting the file - On a directory: Allows creating, deleting, or renaming files within it

x (execute): - On a file: Allows running the file as a program or script - On a directory: Allows entering (cd into) the directory and accessing files within it

The Three User Categories

Permissions are managed for three different categories of users:

  1. u (User/Owner): The person who owns the file or directory
  2. g (Group): Any user who is a member of the owning group
  3. o (Others): Everyone else on the system

Understanding ‘ls -l’ Output

When you use ls -l, the first column shows the file type and permissions:

-rw-r--r--

Let’s break it down:

So, -rw-r--r-- means: a regular file where the owner can read/write, and the group and others can only read.

Changing Permissions with ‘chmod’

The chmod command (change mode) modifies file permissions.

Symbolic Mode (easier for beginners):

chmod u+x my_script.sh        # Add execute permission for owner
chmod go-w sensitive_file.txt # Remove write permission from group & others
chmod a=r new_document.txt    # Set read-only for everyone
chmod +x my_script.sh         # Add execute for all

Octal (Numeric) Mode:

Each permission has a numeric value: - r = 4 (read) - w = 2 (write) - x = 1 (execute) - - = 0 (no permission)

Sum these values for each category (user, group, others):

Permission User Group Others Command
Owner rwx, Group r-x, Others r-x 7 5 5 chmod 755 file
Owner rw-, Group r–, Others r– 6 4 4 chmod 644 file
Owner rwx, Group —, Others — 7 0 0 chmod 700 file

Common Examples:

chmod 755 my_script.sh    # Executable scripts and directories
chmod 644 my_file.txt     # Regular files (owner modify, others read)
chmod 700 private_folder/ # Only owner can access

Changing Ownership with ‘chown’ and ‘chgrp’

chown newuser file.txt           # Change user owner to 'newuser'
chown -R newuser directory/      # Change owner recursively
chown newuser:newgroup file.txt  # Change both user and group owner

chgrp newgroup file.txt          # Change group owner to 'newgroup'
chgrp -R newgroup directory/     # Change group recursively

User & Group Management

Identifying Yourself

whoami    # Show your current username (e.g., 'root')

id        # Show user ID (UID), group ID (GID), and all groups
id user   # Show details for a specific user

Managing User Accounts

adduser newuser       # Create a new user account (interactive)

deluser username      # Delete user, keeps home directory
deluser -r username   # Delete user AND their home directory

passwd                # Change your own password
passwd username       # Change another user's password (as root)

Example of adduser:

alpine:~# adduser mynewuser
Changing password for mynewuser
New password:
Retype password:
passwd: password for mynewuser changed by root
Add 'mynewuser' to additional groups? [y/N]: y
Enter groups to add 'mynewuser' to: wheel

Understanding Groups

groups                # Show groups of the current user
groups username       # Show groups of 'username'

Common groups: - root: The superuser group - wheel: Often grants ‘sudo’ access - users: Default group for regular users


Basic Commands Reference

ls          # List directory contents
            - ls          (List files)
            - ls -l       (Long format, shows details)
            - ls -a       (Show all files, including hidden)
            - ls -alF     (Detailed view with indicators)

pwd         # Print working directory (show current location)

cd          # Change directory
            - cd <dirname>  (Go into specific directory)
            - cd ..         (Go up one directory level)
            - cd            (Go to home directory)
            - cd /          (Go to root directory)

mkdir       # Make directory (create new folder)
            - mkdir my_folder
            - mkdir -p parent/child  (Create parent if needed)

rmdir       # Remove empty directory
            - rmdir empty_folder

File Management Commands

touch       # Create empty file or update timestamp
            - touch my_file.txt

cp          # Copy files or directories
            - cp source.txt destination.txt
            - cp -r my_folder/ new_location/

mv          # Move or rename files or directories
            - mv old_name.txt new_name.txt
            - mv file.txt /path/to/new_location/

rm          # Remove (delete) files or directories (USE WITH CAUTION!)
            - rm unwanted_file.txt
            - rm -r unwanted_folder/
            - rm -rf dangerous_folder/  (Force remove - BE CAREFUL!)

Viewing & Searching File Content

cat         # Concatenate and display file content (good for small files)
            - cat my_file.txt

less        # View file page by page (good for large files)
            - less large_log_file.log
            - (Press Space to scroll, 'q' to quit)

head        # Display beginning of a file
            - head file.txt        (First 10 lines)
            - head -n 5 file.txt   (First 5 lines)

tail        # Display end of file (useful for logs)
            - tail log_file.log       (Last 10 lines)
            - tail -n 20 log_file.log (Last 20 lines)
            - tail -f log_file.log    (Follow new lines)

grep        # Search for patterns in files
            - grep "keyword" my_file.txt
            - grep -i "keyword" my_file.txt (Case-insensitive)
            - grep -r "keyword" /path/to/folder (Recursive)

find        # Search for files and directories
            - find . -name "*.txt"
            - find / -type d -name "config"

System Information & Utilities

whoami      # Show current logged-in username

id          # Show user ID, group ID, and all groups

date        # Display current date and time

clear       # Clear the terminal screen

history     # Show your command history
            - !<number>  (Run command from history)
            - !<string>  (Run last command starting with string)

echo        # Display a line of text
            - echo "Hello, Linux!"
            - echo $PATH  (Display environment variable)

man         # Manual pages - get detailed help
            - man ls  (Shows manual for 'ls' command)

apk         # Alpine Linux package manager
            - apk update           (Update list of packages)
            - apk add <package>    (Install a package)
            - apk search <keyword> (Search for packages)

poweroff    # Shut down the system cleanly

reboot      # Restart the system cleanly

exit        # Exit the current shell session (logs you out)

Remember: Use Tab for auto-completion! It saves typing and avoids typos.


Networking Basics

Checking Connectivity: ‘ping’

ping google.com    # Ping a website
ping 8.8.8.8       # Ping a public DNS server by IP address

How to stop ping: - Press Ctrl+C

Example output:

PING google.com (142.250.186.206): 56 data bytes
64 bytes from 142.250.186.206: seq=0 ttl=116 time=21.606 ms
64 bytes from 142.250.186.206: seq=1 ttl=116 time=21.579 ms
--- google.com ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 21.579/21.592/21.606 ms

Finding Your IP Address: ‘ip a’ or ‘ip addr’

ip a          # Display network interfaces and their IP addresses
ip addr       # Alternative syntax

Example output:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500
    link/ether 52:54:00:12:34:56 brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0

Key things to look for: - lo (Loopback): Virtual interface, always 127.0.0.1 - eth0: Main Ethernet network interface - inet 10.0.2.15/24: Your VM’s IP address and subnet mask - state UP: Network interface is active

Displaying the Routing Table: ‘ip r’ or ‘ip route’

ip r          # Show kernel routing table
ip route      # Alternative syntax

Example output:

default via 10.0.2.2 dev eth0
10.0.2.0/24 dev eth0 scope link  src 10.0.2.15

Key things to look for: - default via 10.0.2.2 dev eth0: Your Default Gateway - This is your “router” for the VM - All traffic for unknown networks goes here

Fetching Webpages: ‘curl’

curl example.com                    # Fetch HTML content
curl -O google.com/index.html       # Download index.html
curl ifconfig.me                    # Show your external IP address

Example usage:

alpine:~# curl example.com
<!doctype html>
<html>
<head>
    <title>Example Domain</title>
... (HTML content will scroll by)

Networking Troubleshooting


Quick Reference Summary

File & Directory Operations

ls -la              # List all files with details
pwd                 # Show current directory
cd /path            # Change directory
mkdir dirname       # Create directory
rm -rf dirname      # Delete directory (use with caution!)
cp file1 file2      # Copy file
mv file1 file2      # Rename/move file
cat file            # Display file content
grep pattern file   # Search in file
find . -name "*.txt" # Find files by pattern
chmod 755 file      # Change permissions (executable)
chmod 644 file      # Change permissions (regular file)
chown user:group file # Change ownership

User & System

whoami              # Current user
id                  # User and group IDs
adduser newuser     # Create new user
passwd              # Change password
groups              # Show user's groups
date                # Show date/time
df -h               # Disk space usage
free -h             # Memory usage
ps aux              # List running processes
top                 # System monitor

Package Management (Alpine)

apk update          # Update package database
apk search package  # Search for package
apk add package     # Install package
apk del package     # Remove package
apk info            # List installed packages

Networking

ping 8.8.8.8        # Test connectivity
ip a                # Show IP addresses
ip r                # Show routing table
curl example.com    # Fetch URL

Learning Tips

  1. Use Tab for auto-completion - Saves typing and avoids typos
  2. Use ‘man’ command - man ls shows help for any command
  3. Start simple - Master basic commands before complex ones
  4. Practice safely - Use test directories, be careful with rm -rf
  5. Experiment - The VM is isolated, so you can’t break the host

Last Updated: December 5, 2025

← Back to Environment Hub