← Back to Script House

Linux & Bash Lab

Hands-on exercises in command line navigation, file operations, and shell scripting

0 of 6 exercises completed
1
Navigation & Reconnaissance
Pending

Finding Your Way

The command line is your window into the system. Learning to navigate efficiently is the foundation of all Linux skills.

# Essential navigation commands $ pwd # Print Working Directory $ ls -la # List all files with details $ cd /var/log # Change to absolute path $ cd .. # Go up one directory $ cd ~ # Go to home directory $ cd - # Go to previous directory # Information gathering $ whoami # Current user $ id # User ID and group memberships $ hostname # System name $ uname -a # Kernel and system info

Tasks

CLH-001: Intro CLH-002: Navigation Filesystem Navigator Command Simulator

Practical Challenge

You've SSH'd into a new server. Write the commands you would use to: find out who you are, where you are, what's in the current directory, and what operating system is running.

2
File Operations
Pending

Working with Files

Creating, copying, moving, and deleting files are fundamental operations. Understanding these commands and their options is essential.

# Creating files and directories $ touch newfile.txt # Create empty file $ mkdir -p dir/subdir # Create nested directories # Copying and moving $ cp file.txt backup/ # Copy file to directory $ cp -r dir/ newdir/ # Copy directory recursively $ mv old.txt new.txt # Rename file $ mv file.txt /tmp/ # Move file to new location # Viewing file contents $ cat file.txt # Display entire file $ head -n 10 file.txt # First 10 lines $ tail -f /var/log/syslog # Follow log in real-time $ less largefile.txt # Paginated viewing # Removing (BE CAREFUL!) $ rm file.txt # Delete file $ rm -rf directory/ # Delete directory recursively (dangerous!)

Tasks

CLH-006: Files Lab: Navigation

Safety First!

rm -rf is irreversible. Always double-check paths before executing. Consider using rm -i for interactive confirmation or trash-cli for recoverable deletion.

Scenario

You need to backup the /etc/nginx directory to /backup/nginx-$(date +%Y%m%d), then create a symbolic link /backup/nginx-latest pointing to the new backup. Write the commands.

3
Permissions & Ownership
Pending

Access Control

Linux permissions determine who can read, write, and execute files. Understanding the permission model is critical for security.

# Permission string: -rwxr-xr-x # Breakdown: [type][owner][group][others] # r=read(4), w=write(2), x=execute(1) $ ls -l script.sh -rwxr-xr-x 1 user group 1024 Dec 26 script.sh # Changing permissions $ chmod 755 script.sh # rwxr-xr-x (octal) $ chmod u+x script.sh # Add execute for owner $ chmod go-w file.txt # Remove write from group/others # Changing ownership $ chown user:group file # Change owner and group $ chown -R user dir/ # Recursive ownership change # Special permissions $ chmod u+s /usr/bin/passwd # SUID - run as owner $ chmod g+s /shared/ # SGID - inherit group $ chmod +t /tmp/ # Sticky bit - only owner can delete

Tasks

CLH-007: Permissions Permissions Calculator Lab: User Identity

Security Analysis

A web server needs to: allow the webserver user to read files in /var/www, allow developers (devgroup) to read and write, and prevent everyone else from accessing. What permissions and ownership would you set?

4
Text Processing & Pattern Matching
Pending

The Power of Text

Linux treats everything as text. Mastering grep, sed, awk, and regular expressions unlocks powerful data manipulation capabilities.

# grep - pattern searching $ grep "error" /var/log/syslog # Find lines with "error" $ grep -i "warning" log.txt # Case-insensitive $ grep -r "TODO" src/ # Recursive search $ grep -E "^[0-9]+" file.txt # Extended regex # Pipelines - combining commands $ cat access.log | grep "404" | wc -l 127 $ ps aux | grep nginx | grep -v grep # awk - field processing $ awk '{print $1}' access.log # Print first column $ awk -F: '{print $1}' /etc/passwd # Custom delimiter # sed - stream editing $ sed 's/old/new/g' file.txt # Replace all occurrences $ sed -i 's/foo/bar/g' file.txt # In-place edit

Tasks

CLH-003: Patterns CLH-011: Advanced Grep CLH-009: Text ↔ CLH-010: I/O

Log Analysis Challenge

Write a one-liner to: find all unique IP addresses in an Apache access log, count how many requests each made, sort by count descending, and show the top 10.

5
Process Management
Pending

Managing Running Programs

Understanding processes is essential for troubleshooting and system administration. Learn to monitor, control, and investigate running processes.

# Viewing processes $ ps aux # All processes with details $ ps aux --forest # Show process tree $ top # Interactive process viewer $ htop # Better interactive viewer # Finding processes $ pgrep -a nginx # Find by name $ lsof -i :80 # What's using port 80? # Controlling processes $ kill 1234 # Send SIGTERM (graceful) $ kill -9 1234 # Send SIGKILL (force) $ pkill nginx # Kill by name # Background processes $ ./script.sh & # Run in background $ jobs # List background jobs $ fg %1 # Bring job 1 to foreground $ nohup ./script.sh & # Survives logout

Tasks

CLH-004: Investigation CLH-014: Control Process Visualizer

Troubleshooting Scenario

A web server is unresponsive. Write the commands to: find the web server process, check its resource usage, identify if it's stuck, and restart it gracefully (or forcefully if needed).

6
Shell Scripting
Pending

Automating with Bash

Shell scripts combine commands into reusable programs. Learn to write scripts that automate repetitive tasks and solve complex problems.

#!/bin/bash # Script structure example # Variables NAME="World" echo "Hello, $NAME!" # Conditionals if [ -f "/etc/passwd" ]; then echo "File exists" else echo "File not found" fi # Loops for file in *.log; do echo "Processing: $file" gzip "$file" done # Functions backup_file() { local file=$1 cp "$file" "$file.bak" echo "Backed up: $file" } # Command substitution TODAY=$(date +%Y-%m-%d) HOSTNAME=$(hostname)

Tasks

CLH-008: Scripting Bash Playground CLH-015: Capstone Command Translator

Final Script Challenge

Write a bash script that: takes a directory as an argument, finds all files modified in the last 24 hours, backs them up to a dated archive, and logs the results. Include error handling.

Linux & Bash Lab Complete!

You've mastered command line navigation, file operations, permissions, text processing, and shell scripting.