Hands-on exercises to master Linux 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
pwd - write down what it showsls to see what's in your current folderls -la to see hidden files and detailscd Desktop to go to your Desktop folderpwd again - notice how it changedcd .. to go back up one foldercd ~ to go to your home folder from anywheremkdir practicecd practicemkdir folder1 folder2 folder3ls to verify all 3 folders were createdmkdir -p projects/python/scriptscd projects/python/scriptscd ~/practicetouch notes.txtecho "Hello Linux!" > greeting.txtcat greeting.txtecho "I am learning terminal commands" >> greeting.txtcat greeting.txtecho -e "Line 1\nLine 2\nLine 3" > multiline.txt
The -e flag enables escape characters like \n for newlinecp greeting.txt greeting-backup.txtls to see both filesmv greeting-backup.txt backup.txtmv backup.txt folder1/ls folder1cp -r folder1 folder1-copy
The -r flag means "recursive" - copies everything insidemv folder1/backup.txt .
The dot (.) means "current directory"rm backup.txtlsrmdir folder3 (works because it's empty)rmdir folder1-copy - notice the error! (folder not empty)rm -r folder1-copy
Use rm -ri to be asked before each deletionecho -e "Alice\nBob\nCharlie\nAlice\nDavid\nBob" > names.txtcat names.txt | wc -lcat names.txt | sortcat names.txt | sort | uniqcat names.txt | sort | uniq | wc -lcat names.txt | sort | uniq > unique-names.txtmkdir newproject && cd newproject && pwdls ~/practice | grep ".txt"echo -e "1. First\n2. Second\n3. Third" > list.txt && cat list.txt
This creates the file AND displays it in one commandls ~ | wc -lls ~/practice/*.txt | wc -lecho "Log created on $(date)" > log.txt && cat log.txt
$(date) runs the date command and inserts its outputecho "Current directory: $(pwd)" >> log.txt && cat log.txtcat names.txt | tail -n 3cp notes.txt "notes-$(date +%Y%m%d).txt" && ls
This creates something like notes-20260213.txtcat greeting.txt | wc -wmkdir -p project/{src,docs,tests} && touch project/src/main.py && ls -R project
Curly braces create multiple folders at once!You've completed all Day 2 practice tasks! You're ready for intermediate commands.
Practice searching files with grep and find, managing file permissions, and working with processes.
0 of 0 tasks completed
First, let's create some files to practice with:
mkdir -p ~/practice-day3 && cd ~/practice-day3echo -e "INFO: Server started\nERROR: Connection failed\nINFO: User logged in\nWARNING: Low memory\nERROR: Database timeout\nINFO: Request processed" > server.logecho "print('Hello World')" > script.py && echo "console.log('Hello')" > app.jsmkdir -p docs/tutorials configs && touch docs/readme.txt docs/tutorials/guide.txt configs/settings.confgrep "ERROR" server.loggrep "INFO" server.loggrep -i "error" server.loggrep -n "ERROR" server.loggrep -c "INFO" server.loggrep -v "ERROR" server.loggrep "Hello" *.txt 2>/dev/null
2>/dev/null hides "no such file" errorsfind . -name "*.txt"find . -name "*.py"find . -type dfind . -type ffind . -name "*script*"find ~ -name "*.log" 2>/dev/null | head -5
head -5 shows only first 5 resultsls -l script.pychmod +x script.py && ls -l script.pychmod -w script.py && ls -l script.pyecho "new line" >> script.py
You should get "Permission denied"chmod +w script.pychmod 755 script.py && ls -l script.py
Owner: rwx, Group: r-x, Others: r-xchmod 444 app.js && ls -l app.jschmod 644 app.js && ls -l app.jspsps aux | head -20
head -20 limits output to first 20 linesps aux | grep "bash"top
Press 'q' to quitsleep 300 &
This creates a process that does nothing for 5 minutesps aux | grep "sleep"killall sleep
Or use: kill PID (replace PID with the number)ps aux | grep "sleep"grep "ERROR" server.log | wc -lfind . -name "*.txt" | wc -lfind . -name "*.py" -exec grep -l "Hello" {} \;
-exec runs a command on each file foundps aux --sort=-%mem | head -10grep "ERROR" server.log | sort | uniqfind . -name "*.conf" -exec ls -l {} \;grep -E "INFO|ERROR|WARNING" server.log | cut -d: -f1 | sort | uniq -c
This counts how many of each log type existfind . -mtime -1 -type fecho '#!/bin/bash\necho "test"' > test.sh && chmod +x test.sh && ./test.shfind . -size +1k -type fgrep -B 2 -A 2 "ERROR" server.logfind . -empty -type fps aux --sort=-%cpu | head -5 > cpu-report.txt && cat cpu-report.txtgrep -r "print" --include="*.py" .You've mastered intermediate Linux commands! You're well on your way to becoming a command line pro.