DEV Community

LaTerral Williams
LaTerral Williams

Posted on

๐Ÿ”"I Will Find You..." - Taken (Linux Edition)

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. ๐Ÿ’ผ๐Ÿ”ง

Image description


๐Ÿ“š 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:

  • 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
Enter fullscreen mode Exit fullscreen mode

Image description

๐Ÿ“„ 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
Enter fullscreen mode Exit fullscreen mode

Image description

Image description

๐Ÿ”น 2.2 Create Large Files

fallocate -l 120M largefile1.log
fallocate -l 200M largefile2.log
Enter fullscreen mode Exit fullscreen mode

Image description

yes "Log Entry" | head -n 2000000 > verbose_log.log
Enter fullscreen mode Exit fullscreen mode

โš ๏ธ Caution:

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.


๐Ÿ”น 2.3 Simulate Different File Owners

sudo useradd kim
sudo chown kim:kim usb_dump.txt
ls -l usb_dump.txt
Enter fullscreen mode Exit fullscreen mode

Image description

๐Ÿ”น 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
Enter fullscreen mode Exit fullscreen mode

Image description


๐ŸŽฏ Mission 1: The `find` Command - Your Digital Bloodhound

๐Ÿงช Syntax

find [path] [options] [actions]
Enter fullscreen mode Exit fullscreen mode

๐Ÿ•ต๏ธโ€โ™‚๏ธ 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 {} \;
Enter fullscreen mode Exit fullscreen mode

Image description

Image description

โ— usb_dump.txt still there?

Hmmm... ๐Ÿค” take a look at the file permissions.

Image description

๐Ÿ” 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 {} \;
Enter fullscreen mode Exit fullscreen mode

๐Ÿ“„ Mission 2: `head` & `tail` - Catch the Beginning or End of a File

๐Ÿ“Œ head

head -n 5 ~/taken_mission/documents/suspicious_log.txt
Enter fullscreen mode Exit fullscreen mode

Image description

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
Enter fullscreen mode Exit fullscreen mode

Image description

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
Enter fullscreen mode Exit fullscreen mode
Option Description
-l Line count
-w Word count
-c Byte count
-m Character count
wc -lwm ~/taken_mission/ransom_note.txt
Enter fullscreen mode Exit fullscreen mode

Image description


๐Ÿ” 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
Enter fullscreen mode Exit fullscreen mode

Image description

๐Ÿค” 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!

Image description


๐ŸŽค 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)