Bandit Level 3
Bandit Level 3 — read a file whose name contains spaces by using quoting, escaping or tab completion.
Source: This content is aggregated from overthewire (MIT). Visit the original repository for the latest version.
Level Goal
The password for the next level is stored in a file called --spaces in this filename-- located in the home directory
Commands you may need to solve this level
ls , cd , cat , file , du , find
Helpful Reading Material
Study guide
Level map: logged in as bandit2, find the password for bandit3.
What this level teaches
How the shell splits a command line into words, and how to keep a filename with spaces together.
Key ideas
- Word splitting. The shell breaks a command at every space, so
cat my fileis read as two arguments,myandfile. - Quoting (single or double quotes) and backslash escaping both tell the shell “treat this as one word”.
- Tab completion has the shell finish a name for you, inserting the correct escapes automatically.
How to approach it
lsshows the file. Note how its name appears.- Try the three techniques above on a harmless file first, for example one you create yourself in a
mktemp -ddirectory. - Start typing the name and press Tab. Seeing the escapes the shell inserts is the quickest way to understand them.
Why it matters
Spaces and special characters in filenames cause the classic scripting bugs. Always quoting variables in scripts ("$file") comes directly from this lesson.