Recap of Last Lesson: We logged into the overthewire Bandit 2 after reading the file “readme” located in the /home/bandit1 directory.
Objective: Find the password to the next level
- Password is in a file named ‘spaces in this filename‘
- file is located in the home directory
How to: This is simply a file name we need to read. The problem is we can’t just type ‘cat spaces in this filename’. This is because *nix interprets each space as a separate item. We don’t currently have any variables, objects or commands named ‘spaces, in, this, filename’ so this command doesn’t make sense to our operating system. Which leads us into escape characters.
Escape characters can get kind of tricky and drawn out, so I’ll give you the short and sweet of it. These characters tell the shell to do something OTHER than what it should do. In this shell if you want ‘cat spaces in this filename’ to have its spaces preserved so that ‘spaces in this filename’ is one ITEM then you need to tell it to do so. The backslash () is used to do this. When we type ‘cat spaces in this filename’ the escape character is always BEFORE the character you wish to escape. In another example if we want to remove all items in the current directory we would just type ‘rm *’ but if we typed ‘rm *’ it would remove all the files named *.
Typing each back slash kind of pain in the ass, but *nix shells offer something amazing called “tab completion”. Halfway type a command and hit tab, UNIX will attempt to complete it for you or provide you a list of available files in the current directory or a list of commands aliased for that host. With that, I literally typed ‘cat sp’ and hit tab, my shell automatically filled in the rest for me.
Conclusion: Escape characters are powerful when programming and helpful when dealing with filenames that have funky characters in them. Additionally, tab completion is extremely helpful and if used effectively can really increase the speed in which you traverse through file structures. Try using it with ‘cd’ to move around to different directories within your OS.