← Back to Study Plan

Terminal Practice Tasks

Hands-on exercises to master Linux commands

Day 2: Basic Commands

Practice navigation, file creation, copying, moving, and deleting. Start with the easy tasks and work your way up to the challenges!

0 of 0 tasks completed

Navigation (pwd, ls, cd)

Easy
  • Open the terminal and type pwd - write down what it shows
  • Type ls to see what's in your current folder
  • Type ls -la to see hidden files and details
  • Type cd Desktop to go to your Desktop folder
  • Type pwd again - notice how it changed
  • Type cd .. to go back up one folder
  • Type cd ~ to go to your home folder from anywhere

Creating Folders (mkdir)

Easy
  • Create a folder called "practice" using mkdir practice
  • Go into that folder with cd practice
  • Create multiple folders at once: mkdir folder1 folder2 folder3
  • Use ls to verify all 3 folders were created
  • Create nested folders: mkdir -p projects/python/scripts
  • Navigate into the nested folder: cd projects/python/scripts

Creating & Viewing Files (touch, echo, cat)

Easy
  • Go back to practice folder: cd ~/practice
  • Create an empty file: touch notes.txt
  • Create a file with content: echo "Hello Linux!" > greeting.txt
  • View the file: cat greeting.txt
  • Add another line: echo "I am learning terminal commands" >> greeting.txt
  • View the file again - you should see both lines: cat greeting.txt
  • Create a file with multiple lines: echo -e "Line 1\nLine 2\nLine 3" > multiline.txt The -e flag enables escape characters like \n for newline

Copying & Moving (cp, mv)

Medium
  • Make a copy of your greeting: cp greeting.txt greeting-backup.txt
  • Use ls to see both files
  • Rename the backup: mv greeting-backup.txt backup.txt
  • Move the backup into folder1: mv backup.txt folder1/
  • Verify it moved: ls folder1
  • Copy a whole folder: cp -r folder1 folder1-copy The -r flag means "recursive" - copies everything inside
  • Move the file back: mv folder1/backup.txt . The dot (.) means "current directory"

Deleting (rm, rmdir)

Medium
Be careful! rm permanently deletes files - there's no recycle bin!
  • Delete the backup file: rm backup.txt
  • Verify it's gone with ls
  • Try deleting folder3: rmdir folder3 (works because it's empty)
  • Try rmdir folder1-copy - notice the error! (folder not empty)
  • Delete folder with contents: rm -r folder1-copy Use rm -ri to be asked before each deletion

Piping & Chaining Commands

Medium
Piping (|) sends output of one command to another.
Chaining (&&) runs the next command only if the first succeeds.
  • Create a file with names: echo -e "Alice\nBob\nCharlie\nAlice\nDavid\nBob" > names.txt
  • Count lines in the file: cat names.txt | wc -l
  • Sort the names: cat names.txt | sort
  • Sort and remove duplicates: cat names.txt | sort | uniq
  • Count unique names: cat names.txt | sort | uniq | wc -l
  • Save sorted unique names to a file: cat names.txt | sort | uniq > unique-names.txt
  • Chain commands: Create folder and enter it in one line:
    mkdir newproject && cd newproject && pwd
  • List only .txt files: ls ~/practice | grep ".txt"

Challenge Tasks

Hard
  • Create a numbered list file: echo -e "1. First\n2. Second\n3. Third" > list.txt && cat list.txt This creates the file AND displays it in one command
  • Count how many files are in your home directory: ls ~ | wc -l
  • Find all .txt files and count them: ls ~/practice/*.txt | wc -l
  • Create a log file with timestamp: echo "Log created on $(date)" > log.txt && cat log.txt $(date) runs the date command and inserts its output
  • Append current directory to the log: echo "Current directory: $(pwd)" >> log.txt && cat log.txt
  • Show last 3 lines of a file: cat names.txt | tail -n 3
  • Create a backup with date in filename: cp notes.txt "notes-$(date +%Y%m%d).txt" && ls This creates something like notes-20260213.txt
  • Count words in a file: cat greeting.txt | wc -w
  • Create directory structure and files in one line:
    mkdir -p project/{src,docs,tests} && touch project/src/main.py && ls -R project Curly braces create multiple folders at once!

Amazing work!

You've completed all Day 2 practice tasks! You're ready for intermediate commands.

Day 3: Intermediate Commands

Practice searching files with grep and find, managing file permissions, and working with processes.

0 of 0 tasks completed

Setup: Create Practice Files

Setup

First, let's create some files to practice with:

  • Create a practice directory: mkdir -p ~/practice-day3 && cd ~/practice-day3
  • Create a log file with various entries: echo -e "INFO: Server started\nERROR: Connection failed\nINFO: User logged in\nWARNING: Low memory\nERROR: Database timeout\nINFO: Request processed" > server.log
  • Create some code files: echo "print('Hello World')" > script.py && echo "console.log('Hello')" > app.js
  • Create nested folders with files: mkdir -p docs/tutorials configs && touch docs/readme.txt docs/tutorials/guide.txt configs/settings.conf

Searching with grep

Easy
  • Find all ERROR lines: grep "ERROR" server.log
  • Find all INFO lines: grep "INFO" server.log
  • Case-insensitive search for "error": grep -i "error" server.log
  • Show line numbers: grep -n "ERROR" server.log
  • Count matching lines: grep -c "INFO" server.log
  • Find lines NOT containing ERROR: grep -v "ERROR" server.log
  • Search in all .txt files: grep "Hello" *.txt 2>/dev/null 2>/dev/null hides "no such file" errors

Finding Files with find

Easy
  • Find all .txt files in current directory and subfolders: find . -name "*.txt"
  • Find all .py files: find . -name "*.py"
  • Find only directories: find . -type d
  • Find only files (not directories): find . -type f
  • Find files by partial name: find . -name "*script*"
  • Find in home directory: find ~ -name "*.log" 2>/dev/null | head -5 head -5 shows only first 5 results

File Permissions (chmod)

Medium
Permission numbers: r=4, w=2, x=1. Add them up!
7 = rwx (4+2+1), 5 = r-x (4+1), 4 = r-- (4)
  • View current permissions: ls -l script.py
  • Make script.py executable: chmod +x script.py && ls -l script.py
  • Remove write permission: chmod -w script.py && ls -l script.py
  • Try to edit it (will fail): echo "new line" >> script.py You should get "Permission denied"
  • Restore write permission: chmod +w script.py
  • Set specific permissions (755): chmod 755 script.py && ls -l script.py Owner: rwx, Group: r-x, Others: r-x
  • Set read-only for everyone (444): chmod 444 app.js && ls -l app.js
  • Reset to normal (644): chmod 644 app.js && ls -l app.js

Process Management (ps, top, kill)

Medium
  • Show your running processes: ps
  • Show ALL system processes: ps aux | head -20 head -20 limits output to first 20 lines
  • Find a specific process: ps aux | grep "bash"
  • Open real-time process monitor: top Press 'q' to quit
  • Start a background process: sleep 300 & This creates a process that does nothing for 5 minutes
  • Find its process ID: ps aux | grep "sleep"
  • Kill the sleep process: killall sleep Or use: kill PID (replace PID with the number)
  • Verify it's gone: ps aux | grep "sleep"

Combining grep + find + pipes

Hard
  • Count ERROR lines in log: grep "ERROR" server.log | wc -l
  • Find .txt files and count them: find . -name "*.txt" | wc -l
  • Search for "Hello" in all files found by find:
    find . -name "*.py" -exec grep -l "Hello" {} \; -exec runs a command on each file found
  • Find large processes (sorted by memory): ps aux --sort=-%mem | head -10
  • Extract just ERROR messages and sort them: grep "ERROR" server.log | sort | uniq
  • Find all config files and show their permissions:
    find . -name "*.conf" -exec ls -l {} \;

Challenge Tasks

Hard
  • Create a summary of log types:
    grep -E "INFO|ERROR|WARNING" server.log | cut -d: -f1 | sort | uniq -c This counts how many of each log type exist
  • Find files modified in the last day: find . -mtime -1 -type f
  • Make all .sh files executable: echo '#!/bin/bash\necho "test"' > test.sh && chmod +x test.sh && ./test.sh
  • Find files larger than 1KB: find . -size +1k -type f
  • Search for a pattern and show context (2 lines before/after):
    grep -B 2 -A 2 "ERROR" server.log
  • Find all empty files: find . -empty -type f
  • Create a report of all processes using most CPU:
    ps aux --sort=-%cpu | head -5 > cpu-report.txt && cat cpu-report.txt
  • Recursive search for "print" in all Python files:
    grep -r "print" --include="*.py" .

Outstanding!

You've mastered intermediate Linux commands! You're well on your way to becoming a command line pro.