Linux Terminal Lab

Master essential Linux/Unix command line operations with hands-on exercises

Lab Overview

This lab teaches you essential Linux terminal commands for navigating the file system, managing files and directories, and performing system operations. These commands also work in WSL (Windows Subsystem for Linux), Git Bash, and most Unix-like systems.

Prerequisites: Linux system, WSL on Windows, or access to a Linux terminal
Note: Linux commands are case-sensitive. ls is different from LS

Part 1: Opening the Terminal

Methods to Open Terminal:

Ubuntu/Debian:

  • Ctrl + Alt + T - Direct shortcut
  • Super key → Type "terminal"
  • Right-click desktop → "Open Terminal"

Other Distros:

  • Fedora: Activities → Terminal
  • Arch: Application Menu → Terminal
  • WSL: Type "wsl" in Windows Terminal

Part 2: Navigation Commands

Essential Navigation Commands:

CommandDescriptionExampleWindows Equivalent
pwdPrint working directorypwdcd (without args)
lsList directory contentslsdir
ls -laList all files with detailsls -ladir /a
cd [dir]Change directorycd Documentscd [dir]
cd ~Go to home directorycd ~cd %USERPROFILE%
cd ..Go up one levelcd ..cd ..
cd /Go to root directorycd /cd \
clearClear terminal screenclearcls
treeDisplay directory treetreetree

Exercise 1: Navigation Practice

Part 3: File Management Commands

File Operations:

CommandDescriptionExample
touch [file]Create empty filetouch file.txt
echo "text" > fileCreate file with contentecho "Hello" > greeting.txt
cat [file]Display file contentscat file.txt
less [file]View file page by pageless largefile.txt
head -n [num] [file]View first n lineshead -n 10 file.txt
tail -n [num] [file]View last n linestail -n 10 file.txt
cp [src] [dest]Copy filecp file.txt backup.txt
mv [src] [dest]Move/rename filemv old.txt new.txt
rm [file]Remove filerm unwanted.txt
rm -i [file]Remove with confirmationrm -i important.txt
find [dir] -name [pattern]Find filesfind . -name "*.txt"
grep [pattern] [file]Search in filegrep "error" log.txt

Exercise 2: Complete File Management Project

Project: Create a Linux project structure with multiple files and practice all operations
Step 1: Setup Workspace
Step 2: Create Multiple Files
Step 3: Organize with Directories
Step 4: File Operations
Step 5: Advanced Operations

Part 4: Directory Management

Directory Operations:

CommandDescriptionExample
mkdir [dir]Create directorymkdir newfolder
mkdir -p [path]Create nested directoriesmkdir -p parent/child/grandchild
rmdir [dir]Remove empty directoryrmdir emptyfolder
rm -r [dir]Remove directory and contentsrm -r fullfolder
rm -rf [dir]Force remove (careful!)rm -rf unwanted
cp -r [src] [dest]Copy directorycp -r source/ destination/
mv [old] [new]Move/rename directorymv oldname newname
du -sh [dir]Directory sizedu -sh Documents/
df -hDisk space usagedf -h

Part 5: Permissions & Ownership

Understanding Linux Permissions:

Permission Format: rwxrwxrwx = Owner|Group|Others
r=read(4), w=write(2), x=execute(1)
CommandDescriptionExample
ls -lView permissionsls -l file.txt
chmod [mode] [file]Change permissionschmod 755 script.sh
chmod +x [file]Make executablechmod +x script.sh
chmod -x [file]Remove executechmod -x file.txt
chown [user] [file]Change ownersudo chown user file.txt
chgrp [group] [file]Change groupsudo chgrp staff file.txt
umaskDefault permissionsumask 022

Common Permission Values:

  • 777 - Everyone can read, write, execute (dangerous!)
  • 755 - Owner: all, Others: read+execute (common for executables)
  • 644 - Owner: read+write, Others: read only (common for files)
  • 600 - Owner only: read+write (private files)

Part 6: Process Management

CommandDescriptionExample
psShow running processesps aux
topReal-time process viewertop (q to quit)
htopBetter process viewerhtop (if installed)
kill [PID]Terminate processkill 1234
kill -9 [PID]Force kill processkill -9 1234
killall [name]Kill by namekillall firefox
jobsShow background jobsjobs
bgSend to backgroundbg %1
fgBring to foregroundfg %1
&Run in backgroundcommand &
nohupRun after logoutnohup command &

Part 7: Package Management

Debian/Ubuntu (apt)

  • sudo apt update - Update package list
  • sudo apt upgrade - Upgrade packages
  • sudo apt install [pkg] - Install package
  • sudo apt remove [pkg] - Remove package
  • apt search [term] - Search packages
  • apt list --installed - List installed

RedHat/Fedora (dnf/yum)

  • sudo dnf update - Update system
  • sudo dnf install [pkg] - Install package
  • sudo dnf remove [pkg] - Remove package
  • dnf search [term] - Search packages
  • dnf list installed - List installed
Homebrew (macOS/Linux)
# Install package
brew install <package_name>

# Update Homebrew
brew update

# Upgrade packages
brew upgrade

# Search packages
brew search <package_name>
APT (Ubuntu/Debian)
# Install package
sudo apt install <package_name>

# Update package list
sudo apt update

# Upgrade packages
sudo apt upgrade

# Search packages
apt search <package_name>
YUM/DNF (RedHat/CentOS)
# Install package
sudo yum install <package_name>

# Update packages
sudo yum update

# Search packages
yum search <package_name>

# DNF (newer)
sudo dnf install <package_name>
Tip: Always run update before installing new packages to ensure you get the latest versions

Quick Reference Card

Essential Navigation
  • pwd - Where am I?
  • ls -la - List everything
  • cd ~ - Go home
  • cd .. - Go up
  • clear - Clear screen
File Operations
  • touch file - Create file
  • cat file - View file
  • cp src dest - Copy
  • mv src dest - Move
  • rm file - Delete
Useful Shortcuts
  • Tab - Auto-complete
  • ↑ ↓ - Command history
  • Ctrl+C - Cancel command
  • Ctrl+Z - Suspend process
  • Ctrl+D - Logout/EOF
  • Ctrl+L - Clear screen
  • Ctrl+R - Search history
Piping and Redirection
  • | - Pipe output to next command: ls | grep txt
  • > - Redirect output to file: echo "text" > file.txt
  • >> - Append to file: echo "more" >> file.txt
  • < - Input from file: sort < list.txt
  • 2> - Redirect errors: command 2> errors.log
  • &> - Redirect all output: command &> all.log

Bonus: Useful Tips & Tricks

Command Aliases

Create shortcuts for frequently used commands:

  • alias ll='ls -la' - Create alias
  • alias gs='git status' - Git shortcut
  • Add to ~/.bashrc or ~/.zshrc to make permanent
Wildcards
  • * - Matches any characters: rm *.txt
  • ? - Matches single character: ls file?.txt
  • [abc] - Matches a, b, or c: ls file[123].txt
  • [a-z] - Matches range: ls [a-z]*.txt
Command Chaining
  • ; - Run sequentially: cd /tmp; ls
  • && - Run if previous succeeds: mkdir dir && cd dir
  • || - Run if previous fails: cd dir || mkdir dir
Pro Tip: Use man [command] to read the manual for any command. Press q to quit the manual. Example: man ls