- Регистрация
- 1 Мар 2015
- Сообщения
- 1,481
- Баллы
- 155
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? ?
? Table of Contents
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:
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
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
?️ Actions
? 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
? tail
tail -n 5 ~/taken_mission/documents/suspicious_log.txt
? Mission 3: `wc` - Word Count for the Digital Detective
wc ~/taken_mission/ransom_note.txt
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:
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? ?
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. ??“I don’t know who you are... I don’t know what you want... But I will find you...”
? 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
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
? 2.3 Simulate Different File OwnersCaution:
The command above writes "Log Entry" 2 million times to the verbose_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.
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]
?️
| 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 |
| Action | Description |
|---|---|
| -exec cp {} /path \; | Copy found files |
| -exec mv {} /path \; | Move found files |
| -exec rm {} \; | Delete found files |
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 {} \;
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 -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 |
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!