Hello again, Linux Learners!
Iโm currently leveling up my Linux skills through a training course, and letโs be honest, sometimes the CLI can feel like a maze. But what if Liam Neeson from Taken were your mentor? ๐
โI donโt know who you are... I donโt know what you want... But I will
find
you...โ
In this article, weโre diving into four essential Linux commands. First, weโll create the files and folders we need to practice. You'll be the hero, and your terminal is your weapon of choice. Letโs go full Bryan Mills on these commands. ๐ผ๐ง
๐ Table of Contents
- Setting Up Your Taken-Inspired Practice Environment
- Mission 1: The find Command
- Mission 2: head & tail
- Mission 3: wc
- Final Mission: All Commands, One Operation
- Final Words
โ๏ธ Setting Up Your Taken-Inspired Practice Environment
Before we start running commands, letโs create a mission simulation in your home directory. Weโll generate files with:
- Different names
- Different sizes (small and large)
- Different owners (optional)
- Different folders
Youโll be ready to test find
, head
, tail
, and wc
like a real digital detective.
๐ Step 1: Create Directories
mkdir -p ~/taken_mission/{documents,secure,interrogation-room,kidnapper}
cd ~/taken_mission
๐ Step 2: Create Test Files
๐น 2.1 Regular Text Files
cd documents
echo "Secret USB Data" > usb_dump.txt
echo "clue file 1" > clue1.log
echo "clue file 2" > clue2.log
echo -e "We have your daughter.\nBring $5 million.\nNo police." > ../ransom_note.txt
echo -e "This is line 1\nThis is line 2\nThis is line 3" > suspicious_log.txt
๐น 2.2 Create Large Files
fallocate -l 120M largefile1.log
fallocate -l 200M largefile2.log
yes "Log Entry" | head -n 2000000 > verbose_log.log
โ ๏ธ Caution:
The command above writes"Log Entry"
2 million times to theverbose_log.log
file.๐ซ DO NOT open this file using
cat
,nano
, or a graphical text editor, it could freeze your terminal or system.โ Instead, safely preview the file using:
head verbose_log.log tail verbose_log.log wc -l verbose_log.log
These commands let you inspect the beginning, end, or line count without overloading your system.
๐น 2.3 Simulate Different File Owners
sudo useradd kim
sudo chown kim:kim usb_dump.txt
ls -l usb_dump.txt
๐น 2.4 Add Files to Other Folders
cd ~/taken_mission/kidnapper
echo "Surveillance data" > cam_feed1.log
fallocate -l 150M cam_feed2.log
cd ~/taken_mission
๐ฏ Mission 1: The `find` Command - Your Digital Bloodhound
๐งช Syntax
find [path] [options] [actions]
๐ต๏ธโโ๏ธ Common Options
Option | Description |
---|---|
-name |
Search by name (case-sensitive) |
-iname |
Search by name (case-insensitive) |
-size +100M |
Files larger than 100MB |
-user kim |
Files owned by specific user |
-type f |
Files only |
๐ ๏ธ Actions
Action | Description |
---|---|
-exec cp {} /path \; |
Copy found files |
-exec mv {} /path \; |
Move found files |
-exec rm {} \; |
Delete found files |
๐ฌ Scenario: The USB Drive Mystery
find ~/taken_mission/documents -name "usb_dump.txt"
find ~/taken_mission/documents -size +100M
find ~/taken_mission/documents -name "usb_dump.txt" -exec cp {} ~/taken_mission/secure/ \;
find ~/taken_mission/documents -name "usb_dump.txt" -exec mv {} ~/taken_mission/interrogation-room/ \;
find ~/taken_mission/documents -name "usb_dump.txt" -exec rm {} \;
โ usb_dump.txt still there?
Hmmm... ๐ค take a look at the file permissions.
๐ I'll let you decide how to tackle the file removal...
I changed the owner to root
and then ran the command again using sudo
:
sudo find ~/taken_mission/documents -name "usb_dump.txt" -exec rm {} \;
๐ Mission 2: `head` & `tail` - Catch the Beginning or End of a File
๐ head
head -n 5 ~/taken_mission/documents/suspicious_log.txt
Option | Description |
---|---|
-n N |
Show the first N lines |
-c N |
Show the first N bytes |
-q |
Suppress headers for multiple files |
๐ tail
tail -n 5 ~/taken_mission/documents/suspicious_log.txt
Option | Description |
---|---|
-n N |
Show the last N lines |
-f |
Follow the file in real-time |
-c N |
Show the last N bytes |
๐ข Mission 3: `wc` - Word Count for the Digital Detective
wc ~/taken_mission/ransom_note.txt
Option | Description |
---|---|
-l |
Line count |
-w |
Word count |
-c |
Byte count |
-m |
Character count |
wc -lwm ~/taken_mission/ransom_note.txt
๐ Final Mission: All Commands, One Operation
find ~/taken_mission/documents -type f -name "*.log" -size +100M > ~/taken_mission/suspect_logs.txt
while read file; do
echo "==> $file <=="
tail -n 10 "$file"
wc -l "$file"
done < ~/taken_mission/suspect_logs.txt
๐ค I was curious why the verbose_log.log
file wasnโt being picked up...
๐ก Then it hit me โ 2000000 bytes is only 2 MB, not 200 MB!
๐ค Final Words
These Linux commands arenโt just useful for action movie heroes, theyโre your go-to tools for file ops, log inspection, and automation. Whether you're tracking a villain or just managing your system, remember:
โGood luck...โ โ with your Linux journey!
Top comments (0)