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:
Command | Description | Example | Windows Equivalent |
---|---|---|---|
pwd | Print working directory | pwd | cd (without args) |
ls | List directory contents | ls | dir |
ls -la | List all files with details | ls -la | dir /a |
cd [dir] | Change directory | cd Documents | cd [dir] |
cd ~ | Go to home directory | cd ~ | cd %USERPROFILE% |
cd .. | Go up one level | cd .. | cd .. |
cd / | Go to root directory | cd / | cd \ |
clear | Clear terminal screen | clear | cls |
tree | Display directory tree | tree | tree |
Exercise 1: Navigation Practice
Part 3: File Management Commands
File Operations:
Command | Description | Example |
---|---|---|
touch [file] | Create empty file | touch file.txt |
echo "text" > file | Create file with content | echo "Hello" > greeting.txt |
cat [file] | Display file contents | cat file.txt |
less [file] | View file page by page | less largefile.txt |
head -n [num] [file] | View first n lines | head -n 10 file.txt |
tail -n [num] [file] | View last n lines | tail -n 10 file.txt |
cp [src] [dest] | Copy file | cp file.txt backup.txt |
mv [src] [dest] | Move/rename file | mv old.txt new.txt |
rm [file] | Remove file | rm unwanted.txt |
rm -i [file] | Remove with confirmation | rm -i important.txt |
find [dir] -name [pattern] | Find files | find . -name "*.txt" |
grep [pattern] [file] | Search in file | grep "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:
Command | Description | Example |
---|---|---|
mkdir [dir] | Create directory | mkdir newfolder |
mkdir -p [path] | Create nested directories | mkdir -p parent/child/grandchild |
rmdir [dir] | Remove empty directory | rmdir emptyfolder |
rm -r [dir] | Remove directory and contents | rm -r fullfolder |
rm -rf [dir] | Force remove (careful!) | rm -rf unwanted |
cp -r [src] [dest] | Copy directory | cp -r source/ destination/ |
mv [old] [new] | Move/rename directory | mv oldname newname |
du -sh [dir] | Directory size | du -sh Documents/ |
df -h | Disk space usage | df -h |
Part 5: Permissions & Ownership
Understanding Linux Permissions:
Permission Format:
r=read(4), w=write(2), x=execute(1)
rwxrwxrwx
= Owner|Group|Othersr=read(4), w=write(2), x=execute(1)
Command | Description | Example |
---|---|---|
ls -l | View permissions | ls -l file.txt |
chmod [mode] [file] | Change permissions | chmod 755 script.sh |
chmod +x [file] | Make executable | chmod +x script.sh |
chmod -x [file] | Remove execute | chmod -x file.txt |
chown [user] [file] | Change owner | sudo chown user file.txt |
chgrp [group] [file] | Change group | sudo chgrp staff file.txt |
umask | Default permissions | umask 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
Command | Description | Example |
---|---|---|
ps | Show running processes | ps aux |
top | Real-time process viewer | top (q to quit) |
htop | Better process viewer | htop (if installed) |
kill [PID] | Terminate process | kill 1234 |
kill -9 [PID] | Force kill process | kill -9 1234 |
killall [name] | Kill by name | killall firefox |
jobs | Show background jobs | jobs |
bg | Send to background | bg %1 |
fg | Bring to foreground | fg %1 |
& | Run in background | command & |
nohup | Run after logout | nohup command & |
Part 7: Package Management
Debian/Ubuntu (apt)
sudo apt update
- Update package listsudo apt upgrade
- Upgrade packagessudo apt install [pkg]
- Install packagesudo apt remove [pkg]
- Remove packageapt search [term]
- Search packagesapt list --installed
- List installed
RedHat/Fedora (dnf/yum)
sudo dnf update
- Update systemsudo dnf install [pkg]
- Install packagesudo dnf remove [pkg]
- Remove packagednf search [term]
- Search packagesdnf 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 versionsQuick Reference Card
Essential Navigation
pwd
- Where am I?ls -la
- List everythingcd ~
- Go homecd ..
- Go upclear
- Clear screen
File Operations
touch file
- Create filecat file
- View filecp src dest
- Copymv src dest
- Moverm file
- Delete
Useful Shortcuts
Tab
- Auto-complete↑ ↓
- Command historyCtrl+C
- Cancel commandCtrl+Z
- Suspend processCtrl+D
- Logout/EOFCtrl+L
- Clear screenCtrl+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 aliasalias 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