1.6. Lab: Exploring Your System#

This lab brings together everything you’ve learned in Chapter 1. You’ll navigate your filesystem, examine processes, understand the directory structure, and explore your system’s configuration. By the end, you’ll have a deeper understanding of how your Linux system is organized.

1.6.1. Part 1: Understanding Your Shell Environment#

1.6.1.1. Exercise 1.1: Know Your Shell#

Run these commands to understand your shell environment:

# See which shell you're using
$ echo $SHELL

# See your shell's PID
$ echo $$

# See all running shells
$ ps | grep bash

# View your shell's configuration file
$ cat ~/.bashrc

# See your command history
$ history | head -20

Questions:

  1. What shell are you running?

  2. What’s your shell’s process ID?

  3. Can you find your shell in the process list?

  4. What aliases are defined in your .bashrc?

1.6.1.2. Exercise 1.2: Explore Your Home Directory#

# Go to your home directory
$ cd ~
$ pwd

# See all files including hidden ones
$ ls -la

# See how much space you're using
$ du -sh ~

# List subdirectories
$ ls -d */

Questions:

  1. What’s your home directory path?

  2. How many hidden files do you have?

  3. What directories are in your home?

  4. Which directory uses the most space?

1.6.1.3. Exercise 1.3: Check Your User Information#

# See your username
$ whoami

# See your user ID and groups
$ id

# See all users on the system
$ cat /etc/passwd | head

# See your user's line in passwd
$ grep $(whoami) /etc/passwd

# See what groups you're in
$ groups

# See all groups
$ cat /etc/group | head

Questions:

  1. What’s your user ID (UID)?

  2. What’s your primary group?

  3. What groups do you belong to?

  4. What shell is listed in /etc/passwd for your user?

1.6.2. Part 2: Navigating the Filesystem Hierarchy#

1.6.2.1. Exercise 2.1: Explore the Root Filesystem#

# Go to root
$ cd /

# List top-level directories
$ ls -la

# See size of each top-level directory
$ du -sh /*

# Look at specific directories
$ ls -la /bin | head
$ ls -la /usr/bin | head
$ ls -la /etc | head

Questions:

  1. How many directories are in the root filesystem?

  2. Which top-level directory is the largest?

  3. How many programs are in /bin?

  4. How many programs are in /usr/bin?

1.6.2.2. Exercise 2.2: Examine System Configuration#

# See the system hostname
$ cat /etc/hostname

# See IP address mappings
$ cat /etc/hosts

# See available shells
$ cat /etc/shells

# See important system info
$ uname -a

# See kernel version
$ cat /proc/version

# See CPU info
$ cat /proc/cpuinfo | head -20

# See memory info
$ cat /proc/meminfo | head -10

# See OS info
$ cat /etc/os-release

Questions:

  1. What’s your system’s hostname?

  2. What OS and kernel version are you running?

  3. How many CPU cores do you have?

  4. How much total memory does your system have?

1.6.2.3. Exercise 2.3: Find Important Directories#

# Find where Python is installed
$ which python3

# Find where your shell is
$ which bash

# Find all Python-related files in /usr
$ find /usr -name "*python*" -type f | head -10

# See what's in /opt (optional software)
$ ls -la /opt

# Check what's mounted
$ mount | grep -E '^/dev'

# See available disks
$ df -h

Questions:

  1. Where is Python installed?

  2. How much disk space is used and available?

  3. What mount points do you see?

  4. What optional software is installed in /opt?

1.6.3. Part 3: Understanding Processes#

1.6.3.1. Exercise 3.1: View Your Processes#

# See your current processes
$ ps

# See all processes with details
$ ps aux

# See process tree (hierarchical view)
$ ps f

# See just your bash process
$ ps -p $$

# See processes in tree format
$ pstree -p

Questions:

  1. What processes are currently running as your user?

  2. Which process is your shell?

  3. What’s the parent process of your shell?

  4. How many total processes are running on the system?

1.6.3.2. Exercise 3.2: Monitor System Activity#

# View top processes by CPU and memory
$ top -b -n 1 | head -20

# See which processes are using the most memory
$ ps aux --sort=-%mem | head -10

# See which processes are using the most CPU
$ ps aux --sort=-%cpu | head -10

# Check system uptime and load
$ uptime

# See how many processes are running
$ ps aux | wc -l

Questions:

  1. Which process is using the most memory?

  2. What’s your system’s load average?

  3. How long has your system been running?

  4. How many total processes exist on your system?

1.6.3.3. Exercise 3.3: Examine Process Details#

# Get detailed information about a process
$ ps aux | grep bash

# See the command line of a specific process
$ cat /proc/$$/cmdline

# See environment variables for a process
$ cat /proc/$$/environ | tr '\0' '\n' | head -10

# See open files for a process
$ lsof -p $$

# See memory map of a process
$ cat /proc/$$/maps | head -10

Questions:

  1. What’s the full command line of your shell?

  2. What environment variables does your shell have?

  3. What files does your shell have open?

  4. How much memory is your shell using?

1.6.4. Part 4: Hands-On Filesystem Navigation#

1.6.4.1. Exercise 4.1: Create and Organize Test Files#

# Create a test directory in your home
$ mkdir -p ~/lab_test/documents ~/lab_test/scripts ~/lab_test/data

# Create some test files
$ touch ~/lab_test/documents/notes.txt
$ touch ~/lab_test/scripts/backup.sh
$ touch ~/lab_test/data/results.csv

# View the structure
$ tree ~/lab_test            # or use: find ~/lab_test

# Check directory sizes
$ du -sh ~/lab_test/*

# List everything with details
$ ls -lR ~/lab_test

Questions:

  1. How many files did you create?

  2. What’s the full path to your test directory?

  3. How much space is each subdirectory using?

1.6.4.2. Exercise 4.2: Practice Path Navigation#

# Start in home
$ cd ~
$ pwd

# Navigate using absolute path
$ cd /usr/bin
$ pwd

# Go up one level
$ cd ..
$ pwd

# Go back to previous directory
$ cd -
$ pwd

# Go home quickly
$ cd
$ pwd

# Go to root then back to home
$ cd /
$ pwd
$ cd ~
$ pwd

Questions:

  1. What’s the parent directory of /usr/bin?

  2. Can you navigate to /usr/bin using a relative path from your home?

1.6.4.3. Exercise 4.3: File Searching and Exploration#

# Find all .sh files in your home
$ find ~ -name "*.sh"

# Find large files (over 10MB)
$ find ~ -size +10M

# Find recently modified files
$ find ~ -mtime -1

# Search for a specific filename
$ find / -name "bash" 2>/dev/null

# Find files modified by you
$ find ~ -user $(whoami)

# See what files are open by your shell
$ lsof -p $$

Questions:

  1. How many shell script files are in your home?

  2. What’s the most recently modified file in your home?

  3. Where is the bash executable located?

1.6.5. Part 5: System Information Deep Dive#

1.6.5.1. Exercise 5.1: Comprehensive System Information#

# Basic system info
$ uname -a

# OS information
$ cat /etc/os-release

# Hostname and network info
$ hostname
$ hostnamectl              # On systemd systems
$ cat /etc/hostname

# CPU information
$ nproc                    # Number of processors
$ lscpu                    # Detailed CPU info
$ cat /proc/cpuinfo

# Memory information
$ free -h                  # Human-readable memory
$ cat /proc/meminfo

# Disk space
$ df -h                    # Mounted filesystems
$ du -sh /*                # Size of top-level directories
$ lsblk                    # Block devices

# Uptime and system load
$ uptime
$ w                        # Who's logged in and system load

Questions:

  1. How many CPU cores does your system have?

  2. How much total memory and swap does your system have?

  3. How much disk space is used and available?

  4. How long has your system been running?

1.6.5.2. Exercise 5.2: Examine System Logs#

# View recent system messages
$ sudo tail -20 /var/log/syslog

# View login history
$ sudo tail -20 /var/log/auth.log

# See kernel messages
$ dmesg | tail -20

# List available log files
$ ls -lh /var/log/

# Search for errors in logs
$ sudo grep -i error /var/log/syslog | head -10

# Monitor logs in real-time
$ sudo tail -f /var/log/syslog

Questions:

  1. What were the last 5 logins on your system?

  2. Are there any error messages in the system log?

  3. What log files exist in /var/log?

1.6.5.3. Exercise 5.3: Understand Boot and Startup#

# See kernel boot parameters
$ cat /proc/cmdline

# See boot messages
$ dmesg | head -30

# Check systemd units
$ systemctl list-units --type=service | head

# See running services
$ systemctl list-units --type=service --state=running | head

# Check system startup time
$ systemd-analyze          # Total boot time
$ systemd-analyze blame    # Services sorted by startup time

Questions:

  1. What’s the total system boot time?

  2. Which service takes the longest to start?

  3. What kernel parameters were used at boot?

1.6.6. Part 6: Challenge Exercises#

These challenges require you to combine what you’ve learned:

1.6.6.1. Challenge 6.1: Find and Analyze a System Process#

Task: Pick a running system process and investigate it thoroughly.

# First, see what's running
$ ps aux

# Pick an interesting process (like systemd, sshd, etc.)
# Then investigate it using:
$ ps -p <PID>
$ cat /proc/<PID>/status
$ cat /proc/<PID>/cmdline | tr '\0' ' '
$ lsof -p <PID> | head -20
$ cat /proc/<PID>/maps | head -10

Report:

  • What process did you choose?

  • Who owns it?

  • What’s its full command line?

  • How much memory does it use?

  • What files does it have open?

1.6.6.2. Challenge 6.2: Create a System Information Script#

Task: Create a script that gathers system information.

# Create a file
$ cat > ~/system_info.sh << 'EOF'
#!/bin/bash
echo "=== System Information ==="
echo "Hostname: $(hostname)"
echo "Kernel: $(uname -r)"
echo "CPU cores: $(nproc)"
echo "Memory: $(free -h | grep Mem | awk '{print $2}')"
echo "Disk usage: $(df -h / | tail -1 | awk '{print $5}')"
echo "Uptime: $(uptime -p)"
echo "Load average: $(uptime | awk -F'load average:' '{print $2}')"
EOF

# Make it executable
$ chmod +x ~/system_info.sh

# Run it
$ ~/system_info.sh

Questions:

  1. What information does your script display?

  2. Can you modify it to show additional information?

1.6.6.3. Challenge 6.3: Analyze Directory Usage#

Task: Find which directories use the most space.

# Find large directories in home
$ du -sh ~/* | sort -rh | head -10

# Find large directories in root (requires root for some)
$ sudo du -sh /* | sort -rh

# Find the largest files in your home
$ find ~ -type f -exec du -h {} + | sort -rh | head -20

# Find large files system-wide
$ sudo find / -type f -size +100M -exec du -h {} + | sort -rh | head -10

Report:

  1. Which directory in your home uses the most space?

  2. What’s the largest file in your home?

  3. Where are the largest files on your system?

1.6.7. Part 7: Cleanup and Reflection#

1.6.7.1. Exercise 7.1: Clean Up#

After exploring, clean up your test files:

# Remove the test directory you created
$ rm -r ~/lab_test/

# Remove the script you created
$ rm ~/system_info.sh

# Verify they're gone
$ ls ~/

1.6.7.2. Exercise 7.2: Reflection Questions#

Answer these questions based on your exploration:

  1. Shell and Processes:

    • What shell are you using, and how did you find this information?

    • Explain the parent-child relationship between your terminal and your shell.

    • What’s the difference between a process running in the foreground vs background?

  2. Filesystem Hierarchy:

    • Why is the filesystem organized hierarchically?

    • Where would you look if you wanted to find all user programs?

    • Why can’t you delete /tmp or /var/log without consequences?

  3. System Understanding:

    • What’s the relationship between the kernel and shell?

    • How does the kernel protect different processes from interfering with each other?

    • Why do some commands require sudo while others don’t?

  4. Practical Application:

    • How would you find out if your system is running low on disk space?

    • How would you investigate a process that’s using too much memory?

    • Where would you look if something went wrong on your system?

1.6.8. Key Takeaways from the Lab#

Your system is organized logically — Each directory has a specific purpose
Everything is a process — Even your shell; you can inspect and control them
Logs tell the story — When things go wrong, check /var/log
Information is accessible — Use ps, df, du, /proc to understand your system
Tools are composable — Combine simple commands to answer complex questions

1.6.9. Next Steps#

Now that you understand the Linux system fundamentals, you’re ready to:

  • Learn more advanced filesystem operations (permissions, linking, etc.)

  • Write shell scripts to automate tasks

  • Understand how programs interact with the system

  • Troubleshoot system problems

The foundation you’ve built in this chapter is essential for everything that follows.