OverTheWire Bandit: Level 7 → Level 8
Context
We used find to locate a file in the system. But what if we know where the file is, but its content is huge?
The data.txt file in this level contains thousands of lines. If you try to read it with cat data.txt, your terminal will be flooded with scrolling text, making it impossible to spot what you’re looking for (and potentially freezing your terminal!).
This level introduces grep, the fundamental tool for text mining in Linux.
Goal
The password is stored in the file data.txt, right next to the word “millionth”.
Solution
Instead of drowning in data with cat, let’s filter the file. The grep command searches for a specific pattern within a text and prints only the lines matching that pattern.
Our command structure:
grep: “Global Regular Expression Print”.millionth: The keyword we are searching for.data.txt: The file to search in.
grep "millionth" data.txt
Output:
millionth TESKZC0XvTetK0S9xNwm25STk5iWrBvP
As you can see, thousands of lines were filtered out, leaving only the single line containing “millionth”. The password is right there next to it.
Key Takeaways
grepvsfind:find: Used to locate files in the file system (by name, size, etc.).grep: Used to search for text inside a file.
- Working with Large Files: Never blindly use
caton files if you don’t know their size or content. Prefer filtering withgrepor viewing piece-by-piece with commands likeheadorless.