~$ skillshelf
← OverTheWire Bandit

Bandit 4 → 5: file before cat

banditlinuxshell

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 inhere directory.

the approach

bandit4@bandit:~$ cd inhere
bandit4@bandit:~/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:

bandit4@bandit:~/inhere$ 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:

bandit4@bandit:~/inhere$ file ./-file*
./-file00: data
./-file01: data
...
./-file07: ASCII text
...

One ASCII text in a wall of data. That’s the one:

bandit4@bandit:~/inhere$ cat ./-file07

I leaned on an AI for the flags on this level. I’m deliberately learning the CLI with one at my elbow rather than pretending otherwise — but the point is to come out the other side knowing file exists, not to have a transcript where the answer appeared.

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.