Bandit 4 → 5: file before cat
Ten candidate files and only one you can read. You could cat your way through
them, but nine of those are binary and will chew up your terminal. There’s a
command whose entire job is answering “what is this?” without opening it.
the goal
The password for the next level is stored in the only human-readable file in the
inheredirectory.
the approach
cd inhere && ls -f
-file00 -file01 -file02 -file03 -file04
-file05 -file06 -file07 -file08 -file09
Ten files, and every one of them starts with a dash — the level 1 problem, times ten. Same fix, except now a glob covers all of them at once:
ls ./-file*
Then instead of reading them, ask what they are. file peeks at the first few
bytes and reports what it thinks each one is, without printing the contents:
file ./-file*
./-file00: data
./-file01: data
...
./-file07: ASCII text
...
One ASCII text in a wall of data. That’s the one:
cat ./-file07
the takeaway
file before cat. When you don’t know what’s in front of you, file *
classifies everything in one pass, costs nothing, and doesn’t dump binary into
your scrollback. It’s the cheapest way to go from ten candidates to one.
And the ./ from level 1 keeps earning its keep: any time a glob might expand to
names starting with -, putting ./ in front of the glob makes the whole
expansion safe at once.