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:
What shell are you running?
What’s your shell’s process ID?
Can you find your shell in the process list?
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:
What’s your home directory path?
How many hidden files do you have?
What directories are in your home?
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:
What’s your user ID (UID)?
What’s your primary group?
What groups do you belong to?
What shell is listed in /etc/passwd for your user?
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:
What processes are currently running as your user?
Which process is your shell?
What’s the parent process of your shell?
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:
Which process is using the most memory?
What’s your system’s load average?
How long has your system been running?
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:
What’s the full command line of your shell?
What environment variables does your shell have?
What files does your shell have open?
How much memory is your shell using?
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:
How many CPU cores does your system have?
How much total memory and swap does your system have?
How much disk space is used and available?
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:
What were the last 5 logins on your system?
Are there any error messages in the system log?
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:
What’s the total system boot time?
Which service takes the longest to start?
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:
What information does your script display?
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:
Which directory in your home uses the most space?
What’s the largest file in your home?
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:
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?
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
/tmpor/var/logwithout consequences?
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
sudowhile others don’t?
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.