Linux CLI Drills: Files, Pipes, Processes & Ports


Introduction
The Linux command line interface (CLI) is one of the most powerful tools every developer should know. Recently, I completed a set of CLI practice drills that covered filesystem manipulation, pipes, processes, ports, and package management.
In this post, Iβll walk through the commands I used, explain what they do, and share key takeaways from each section.
π Drill 1 β File System
1. Create the directory structure
mkdir -p hello/five/six/seven
mkdir -p hello/one/two/three/four
touch hello/five/six/c.txt
touch hello/five/six/seven/error.log
touch hello/one/a.txt hello/one/b.txt hello/one/two/d.txt
touch hello/one/two/three/e.txt hello/one/two/three/four/access.log
2. Delete .log
files
find hello -type f -name "*.log" -delete
3. Add text to a.txt
echo "Unix is a family of multitasking, multiuser computer operating systems ..." > hello/one/a.txt
4. Delete five
directory
rm -rf hello/five
5. Rename one
to uno
mv hello/one hello/uno
6. Move a.txt
to two
directory
mv hello/uno/a.txt hello/uno/two/
Drill 2 β Pipes & Redirection
Download book
curl -o goblet.txt https://raw.githubusercontent.com/.../harry_potter_goblet_of_fire.txt
head -n 3 goblet.txt First 3 lines
tail -n 10 goblet.txt Last 10 lines
Find Occurrences of words:
grep -o -i "Harry" goblet.txt | wc -l
grep -o -i "Ron" goblet.txt | wc -l
grep -o -i "Hermione" goblet.txt | wc -l
grep -o -i "Dumbledore" goblet.txt | wc -l
sed -n '100,200p' goblet.txt Lines 100β200
Unique words:
tr ' ' '\n' < goblet.txt | tr -d '[:punct:]' | tr '[:upper:]' '[:lower:]' | sort | uniq | wc -l
Processes & Ports
List browser processes β
ps -ef | grep -i firefox
Kill browser β
pkill firefox
Top 3 CPU β
ps -eo pid,ppid,cmd,%cpu --sort=-%cpu | head -n 4
Top 3 memory β
ps -eo pid,ppid,cmd,%mem --sort=-%mem | head -n 4
Start HTTP server β
python3 -m http.server 8000
Kill server β
lsof -i :8000 && kill <pid>
Start on port 90 β
sudo python3 -m http.server 90
Show active connections β
netstat -tulnp
PID on 5432 β
lsof -i :5432
Managing Software
- Install:
Install:
sudo apt install htop vim nginx # Ubuntu
brew install htop vim nginx # Mac
Remove:
sudo apt remove nginx # Ubuntu
brew uninstall nginx # Mac
Misc Commands
# 1. Local IP address
Local IP β hostname -I
# 2. IP address of google.com
nslookup google.com
# 3. Check if internet is working
ping -c 4 google.com
# 4.location of commands
which node
which code
Key Learnings
find
,mv
, andrm -rf
are powerful for filesystem work.Pipes (
|
) and redirection (>
,<
) let you chain commands efficiently.ps
,kill
, andnetstat
are essential for managing processes and ports.Package managers (
apt
,brew
) make installing software painless.Misc tools like
ping
,hostname
,which
are super handy for troubleshooting.
Conclusion
These CLI drills gave me a strong foundation in file handling, process management, networking, and software installation using Linux commands. If youβre learning the CLI, I highly recommend practicing these exercises step by step β theyβll save you hours in real-world debugging.
Subscribe to my newsletter
Read articles from Mohd Asif directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
