Reference library
Find a command by what you need to do.
These examples come from the same catalog used by the course. Search here for syntax, then open the linked mission to learn the command in context.
98 guided examples
Navigation & files
Where am I?
Prints your current folder.
pwdNavigation & files
Identify your Linux environment
Shows the kernel, architecture, distribution details, and (when applicable) the WSL distribution name. These checks are safe on Ubuntu, most Linux distributions, and WSL.
uname -srmo
cat /etc/os-release
if [ -n "$WSL_DISTRO_NAME" ]; then echo "WSL distro: $WSL_DISTRO_NAME"; fiNavigation & files
List files
Shows files in normal, detailed, hidden, human-readable, and time-sorted views.
ls
ls -l
ls -la
ls -lh
ls -ltrNavigation & files
Create first practice items
Creates harmless files and a folder inside the sandbox.
touch file1.txt file2.txt file3.txt
mkdir testdir
ls -laNavigation & files
Move to home and back
Moves home, then returns to the sandbox.
cd ~
pwd
cd ~/linux-practice
pwdNavigation & files
Practice parent folders
Shows how .. climbs up one level at a time.
cd ~/linux-practice
mkdir -p files/demo
cd files/demo
pwd
cd ..
pwd
cd ../..
pwdNavigation & files
Return to previous directory
cd - switches back to the last directory you were in, without retyping the path.
cd ~/linux-practice
cd /tmp
pwd
cd -
pwdNavigation & files
Read-only visit to /etc
Visits Ubuntu configuration folders without editing anything.
cd /etc
pwd
ls -l | head -20
cd ~/linux-practiceNavigation & files
Create files
Creates empty files and demonstrates brace expansion.
cd ~/linux-practice
touch myfile.txt
touch file_{1..5}.txt
ls -lNavigation & files
Create and remove empty directories safely
mkdir -p creates missing parent folders without failing when they already exist. rmdir removes only an empty directory, making it a safer first removal command than rm -r.
cd ~/linux-practice
mkdir -p files/{inbox,archive}
ls -ld files files/inbox files/archive
rmdir files/archiveNavigation & files
Inspect file metadata
Shows size, permissions, owner, timestamps, and inode.
stat myfile.txtNavigation & files
Identify file type
Compares a text file with a real executable.
echo 'Hello Ubuntu' > myfile.txt
file myfile.txt
file /bin/bashNavigation & files
Write and append
Creates a file and appends another line. Remember: > overwrites.
cd ~/linux-practice
echo 'First line' > journal.txt
echo 'Second line' >> journal.txt
cat journal.txtNavigation & files
Number and reverse lines
Shows numbered lines and reverse order.
cat -n journal.txt
tac journal.txtNavigation & files
Save output with tee
Saves a directory listing while also displaying it.
ls -la | tee listing.txt
cat listing.txtNavigation & files
Create a large file
Generates a harmless file for viewing practice.
cd ~/linux-practice
for i in {1..100}; do echo "This is line number $i"; done > large.txtNavigation & files
Preview file parts
Shows first lines, last lines, and counts.
head -n 5 large.txt
tail -n 5 large.txt
wc large.txt
wc -l large.txtNavigation & files
Open with less
Press Space for next page, /pattern to search, and q to quit.
less -N large.txtText & pipelines
Overwrite and append
Demonstrates the difference between replace and append.
cd ~/linux-practice
echo 'First' > output.txt
echo 'Second' >> output.txt
cat output.txtText & pipelines
Capture errors
Sends stderr to a file instead of the screen.
ls missing-file 2> error.log
cat error.logText & pipelines
Use a heredoc
Creates multi-line text safely.
cat << 'EOF' > document.txt
Line 1
Line 2
Variables like $HOME are not expanded here
EOF
cat document.txtText & pipelines
Sort and count
Sorts lines and counts adjacent duplicates after sorting.
cd ~/linux-practice
echo -e 'banana\napple\ncherry\napple' > fruits.txt
sort fruits.txt | uniq -cText & pipelines
Translate characters
Transforms text through a pipeline.
echo 'Hello World' | tr 'a-z' 'A-Z'
echo 'Hello World' | tr ' ' '_'Text & pipelines
Cut and align fields
Extracts fields and prints a simple table.
echo 'Name:Age:City' > people.txt
echo 'Jane:25:London' >> people.txt
cut -d: -f1,3 people.txt
column -t -s: people.txtText & pipelines
Basic grep
Finds matching and non-matching lines.
cd ~/linux-practice
echo -e 'Apple\napple\nAPPLE\nBanana\napricot' > fruits.txt
grep -i 'apple' fruits.txt
grep -v 'apple' fruits.txtText & pipelines
Regex anchors
Uses start, end, and OR matching.
grep '^A' fruits.txt
grep 'e#x27; fruits.txt
grep -E 'apple|Banana' fruits.txtText & pipelines
Recursive search
Searches through folders.
mkdir -p projects/search-demo
echo 'secret pattern' > projects/search-demo/file.txt
grep -r 'pattern' projectsText & pipelines
Substitute safely
Prints changed output without modifying the file.
cd ~/linux-practice
echo -e 'Hello\nWorld\nHello World' > text.txt
sed 's/Hello/Hi/' text.txt
sed 's/Hello/Hi/g' text.txtText & pipelines
Print selected lines
Shows only selected lines.
sed -n '2p' text.txt
sed -n '1,2p' text.txtText & pipelines
In-place with backup
Changes the file and keeps a backup copy.
sed -i.bak 's/Hello/Hi/g' text.txt
cat text.txt
cat text.txt.bakText & pipelines
Print fields
Prints columns and line numbers.
cd ~/linux-practice
echo -e 'Name Age City\nJohn 30 NYC\nJane 25 LA' > data.txt
awk '{print $1, $3}' data.txt
awk '{print NR, $0}' data.txtText & pipelines
CSV separator
Uses comma as a field separator and calculates values.
echo -e 'Product,Price,Quantity\nApple,1.50,100\nBanana,0.75,200' > inventory.csv
awk -F, 'NR>1 {print $1, $2 * $3}' inventory.csvText & pipelines
Total calculation
Accumulates a total and prints it at the end.
awk -F, 'NR>1 {total += $2 * $3} END {print total}' inventory.csvSafety & control
Create search lab
Creates harmless test files.
cd ~/linux-practice
mkdir -p find-lab/subdir/nested
touch find-lab/file1.txt find-lab/file2.pdf find-lab/old.log find-lab/subdir/test.txtSafety & control
Find files
Searches by name and type.
find find-lab -name '*.txt'
find find-lab -type f
find find-lab -type d
find find-lab -emptySafety & control
Act on results
Lists matching files and prints logs before any deletion.
find find-lab -name '*.txt' -exec ls -lh {} \;
find find-lab -name '*.log' -printSafety & control
Delete only after printing
Deletes only the practice .log file after you have confirmed the match.
find find-lab -name '*.log' -deleteSafety & control
Practice chmod
Changes permissions on your own practice file.
cd ~/linux-practice
touch permissions_demo.txt
chmod 644 permissions_demo.txt
ls -l permissions_demo.txt
chmod 600 permissions_demo.txt
ls -l permissions_demo.txtSafety & control
Make a script executable
Adds execute permission to a practice script.
echo 'echo Hello' > scripts/hello.sh
chmod +x scripts/hello.sh
./scripts/hello.shSafety & control
System special bits example
These examples explain SUID and sticky bit. Do not run them; Ubuntu already manages system permissions.
chmod u+s /usr/bin/passwd
chmod +t /tmpSafety & control
Who am I?
Shows your username, IDs, and groups.
cd ~/linux-practice
whoami
id
groupsSafety & control
Inspect ownership
Shows ownership on your file and reads user/group databases.
touch owned-by-me.txt
ls -l owned-by-me.txt
head -5 /etc/passwd
head -5 /etc/groupSafety & control
Optional admin ownership examples
These change real system state. They are explained, not required for this safe course.
sudo chown username:groupname file.txt
sudo adduser testlearner
sudo userdel -r testlearnerSafety & control
View processes
Shows current and system processes.
ps
ps aux | head -15
pgrep -l bashSafety & control
Create and stop a practice job
Starts one harmless background process, captures its exact PID with $!, then stops and waits for that same process. This remains deterministic even when other jobs already exist.
cd ~/linux-practice
sleep 100 &
practice_pid=$!
echo "Started practice PID: $practice_pid"
jobs -l
kill "$practice_pid"
wait "$practice_pid" 2>/dev/null || true
jobs -lSafety & control
Broad process killing examples
Useful but broad. Prefer job number or exact PID while learning.
killall sleep
pkill -f 'sleep 200'Safety & control
Inspect variables
Reads common environment variables.
printenv | head -20
echo $HOME
echo $USER
echo $SHELL
echo $PATHSafety & control
Export a temporary variable
Creates and removes a temporary variable.
export MY_NAME='Linux Learner'
echo $MY_NAME
bash -c 'echo Child sees: $MY_NAME'
unset MY_NAMESafety & control
Practice PATH safely
Temporarily adds your practice bin folder to PATH.
mkdir -p ~/linux-practice/bin
export PATH="$HOME/linux-practice/bin:$PATH"
which ls
whereis bash
type cdSafety & control
Find the command your shell will run
command -v is the portable way to find a command or shell builtin. command -V gives a fuller explanation, while env lists exported variables for the current process.
command -v ls
command -v cd
command -V cd
env | sort | head -20Applied workflows
Create and inspect aliases
Creates a friendly listing shortcut.
alias ll='ls -la'
ll
alias llApplied workflows
Remove aliases
Removes the temporary shortcut.
unalias ll
aliasApplied workflows
Bypass an alias
Runs the original command even if an alias exists.
alias ls='ls --color=auto'
command ls
\lsApplied workflows
View history
Shows recent commands.
history 10Applied workflows
Repeat simple commands
Repeats the previous harmless echo command.
echo 'safe repeat demo'
!!Applied workflows
History clearing example
Clears current shell memory history. Explanation only for most learners.
history -cApplied workflows
Brace expansion
Creates multiple practice files quickly.
echo file_{1..5}.txt
touch file_{1..5}.txt
ls file_*.txtApplied workflows
Globbing lab
Shows common filename patterns.
mkdir -p glob-lab
cd glob-lab
touch a.txt b.txt c.txt 1.txt 22.txt abc.txt
echo *.txt
echo ?.txt
echo [ab].txt
cd ..Applied workflows
Safe cleanup
Removes only the glob-lab folder created in the sandbox.
rm -rf glob-labApplied workflows
Hard link demo
Shows two names for the same file data.
cd ~/linux-practice
echo 'Original content' > original.txt
ln original.txt hardlink.txt
ls -li original.txt hardlink.txt
echo 'Added line' >> original.txt
cat hardlink.txtApplied workflows
Symlink demo
Creates and inspects a symbolic link.
echo 'Target content' > target.txt
ln -s target.txt symlink.txt
ls -l symlink.txt
readlink symlink.txt
cat symlink.txtApplied workflows
Broken symlink
Demonstrates a broken symlink inside the practice folder.
rm target.txt
cat symlink.txtApplied workflows
Create archive lab
Creates a folder to archive.
cd ~/linux-practice
mkdir -p archive-lab/docs
echo 'file1' > archive-lab/file1.txt
echo 'readme' > archive-lab/docs/README.txtApplied workflows
Tar and inspect
Creates a compressed tar archive and lists its contents.
mkdir -p backups
tar -czvf backups/archive-lab.tgz archive-lab
tar -tvf backups/archive-lab.tgzApplied workflows
Extract safely
Extracts into a dedicated restored folder.
mkdir -p restored
tar -xzvf backups/archive-lab.tgz -C restored
ls -R restoredSystem & network
Measure sandbox
Shows size of the practice folder and its contents.
cd ~/linux-practice
du -sh
du -sh * 2>/dev/nullSystem & network
Filesystem free space
Shows root filesystem free space and type.
df -h /
df -hT /System & network
Observe block devices
Reads storage and mount information only.
lsblk
findmnt | head -20
mount | head -20System & network
Read-only package search
Searches and inspects packages without installing anything.
apt search 'text editor' | head -20
apt show nano | head -20
apt list --installed | head -20System & network
Detect your package manager
Checks which common package-manager command is available without changing the system. Follow the APT examples only on Ubuntu, Debian, or their WSL distributions.
command -v apt || true
command -v dnf || true
command -v pacman || true
command -v zypper || trueSystem & network
Inspect installed files
Uses dpkg to inspect installed package information.
dpkg -l | head -20
dpkg -l | grep -i bash
dpkg -L bash | head -20System & network
Optional install/remove pattern
This changes the real Ubuntu system. It is optional and not part of the removable sandbox guarantee.
sudo apt update
sudo apt install sl -y
sudo apt remove slSystem & network
Connectivity checks
Sends ICMP probes to a public address and the local loopback interface. A reply is useful evidence; no reply is inconclusive because networks and hosts may block ICMP.
ping -c 2 8.8.8.8
ping -c 1 localhostSystem & network
Check DNS separately from connectivity
Separates name lookup from ICMP reachability. If the IP address replies but name lookup fails, DNS is the likely layer to investigate. A failed ping alone does not prove the network is offline.
getent hosts example.com
ping -c 1 example.com
ping -c 1 1.1.1.1System & network
Fetch a web page
Downloads into the sandbox downloads folder. -L follows redirects; -I fetches headers only.
mkdir -p ~/linux-practice/downloads
cd ~/linux-practice/downloads
curl -IL https://example.com
curl -L -o example.html https://example.com
head -5 example.htmlSystem & network
Inspect network info
Views addresses, routes, and listening ports.
ip addr show | head -30
ip route show
ss -tuln | head -20
hostname -ISystem & network
Memory and uptime
Shows memory, uptime, and short virtual memory stats.
free -h
uptime
vmstat 1 2System & network
Process snapshots
Shows a non-interactive top snapshot and memory-heavy processes.
top -b -n 1 | head -20
ps aux --sort=-%mem | head -10System & network
Logs and watch
Reads recent logs only when systemd is running, then starts a repeating clock. This handles non-systemd distributions and WSL environments where systemd is disabled. Stop watch with Ctrl+C.
if command -v journalctl >/dev/null && [ "$(ps -p 1 -o comm=)" = systemd ]; then
journalctl -n 20 --no-pager
else
echo "systemd journal is not available in this environment"
fi
watch -n 2 dateAutomation
Hello script
Creates and runs a first script.
cd ~/linux-practice/scripts
cat << 'EOF' > hello.sh
#!/usr/bin/env bash
echo "Hello, $USER!"
echo "Today is $(date)"
echo "You are in $PWD"
EOF
chmod +x hello.sh
./hello.shAutomation
Arguments script
Shows common script argument variables.
cat << 'EOF' > args.sh
#!/usr/bin/env bash
echo "Script name: $0"
echo "First argument: $1"
echo "All arguments: $@"
echo "Number of arguments: $#"
EOF
chmod +x args.sh
./args.sh one two threeAutomation
Exit status
Shows non-zero failure and zero success statuses.
ls /nonexistent
echo "Exit status: $?"
ls /bin/bash
echo "Exit status: $?"Automation
If/else demo
Creates a basic conditional script.
cd ~/linux-practice/scripts
cat << 'EOF' > if_demo.sh
#!/usr/bin/env bash
num=${1:-10}
if [ "$num" -gt 10 ]; then
echo "Greater than 10"
elif [ "$num" -eq 10 ]; then
echo "Exactly 10"
else
echo "Less than 10"
fi
EOF
chmod +x if_demo.sh
./if_demo.sh 25Automation
For loop
Loops over fixed words. Saved in scripts/ alongside if_demo.sh.
cd ~/linux-practice/scripts
cat << 'EOF' > for_demo.sh
#!/usr/bin/env bash
for fruit in apple banana cherry; do
echo "I like $fruit"
done
EOF
chmod +x for_demo.sh
./for_demo.shAutomation
Case statement
Matches one value against multiple patterns. Saved in scripts/ alongside the other demo scripts.
cd ~/linux-practice/scripts
cat << 'EOF' > case_demo.sh
#!/usr/bin/env bash
answer=${1:-yes}
case "$answer" in
yes|y|YES|Y) echo "You agreed." ;;
no|n|NO|N) echo "You disagreed." ;;
*) echo "Invalid input" ;;
esac
EOF
chmod +x case_demo.sh
./case_demo.sh yesAutomation
Read current crontab
Checks that the crontab command exists before listing entries, and distinguishes a missing tool from an empty or inaccessible user crontab. Scheduling also requires a working cron-compatible service.
if ! command -v crontab >/dev/null; then
echo "crontab is not installed in this environment"
else
crontab -l 2>/dev/null || echo "No user crontab exists, or access is unavailable"
fiAutomation
Safe scheduling simulation
Simulates repeated scheduled work without editing crontab.
cd ~/linux-practice
mkdir -p logs
for i in {1..3}; do echo "Simulated run at $(date)" >> logs/schedule-demo.log; sleep 2; done
cat logs/schedule-demo.logAutomation
Dangerous cleanup example
Removes the entire user crontab. Explanation only; do not use as course cleanup.
crontab -rAutomation
Find command info
Discovers command locations, shell builtins, and descriptions. Prefer command -v over which in scripts because command is provided by the shell.
command -v ls
command -V cd
whereis bash
type cd
whatis ls
apropos 'list directory' | head -10Automation
Manual pages
Opens the ls manual. Press q to quit.
man lsAutomation
Optional locate setup
Installs plocate (the modern locate on Ubuntu 22.04+) and updates its database. Optional only.
sudo apt install plocate -y
sudo updatedb
locate bashrc | headApplied workflows
Inspect, do not edit
Reads the beginning of your real .bashrc without changing it.
cat ~/.bashrc | head -30Applied workflows
Temporary prompt
Changes and restores the prompt only in the current shell.
OLD_PS1=$PS1
PS1='Practice> '
echo 'Prompt changed for this session'
PS1=$OLD_PS1Applied workflows
Practice alias file
Sources aliases from a removable practice file.
echo "alias showdate='date +%Y-%m-%d'" >> ~/linux-practice/my_aliases
source ~/linux-practice/my_aliases
showdate
unalias showdateApplied workflows
Real .bashrc edit example
This permanently modifies your real shell startup file. Explanation only in this course.
echo "alias la='ls -A'" >> ~/.bashrcApplied workflows
Create final project
Creates a complete mini project.
cd ~/linux-practice
mkdir -p final_project/{src,docs,bin} backups
cd final_project
echo 'main function' > src/main.c
echo '# README' > docs/README.md
cat << 'EOF' > bin/script.sh
#!/usr/bin/env bash
echo 'Processing...'
for f in src/*; do
echo "Found: $f"
wc -l "$f"
done
EOF
chmod +x bin/script.shApplied workflows
Review skills
Uses archive, find, grep, head, xargs, du, and script execution.
cd ~/linux-practice/final_project
tar -czvf ../backups/final-project-v1.tgz src docs bin
tar -tzf ../backups/final-project-v1.tgz
find . -name '*.sh' -exec ls -lh {} \;
grep -r 'function' .
head -2 docs/README.md
find . -type f \( -name '*.c' -o -name '*.sh' \) -print0 | xargs -0 wc -l
du -sh .
./bin/script.shApplied workflows
Remove final project only
Deletes only final_project inside the sandbox.
cd ~/linux-practice
rm -rf final_project