The password for the next level is stored in a file called spaces in this filename located in the home directory
홈 디렉토리에 있는 파일인 'spaces in this filename'에 비밀번호가 저장되어 있다네요! ls 명령어를 사용하여 확인해 보겠습니다.
bandit2@bandit:~$ ls
spaces in this filename
이것도 그냥 cat, more, vi 등으로 읽으면 되는거 아닌가? 하고 시도해 봅니다.
bandit2@bandit:~$ cat spaces in this filename
cat: spaces: No such file or directory
cat: in: No such file or directory
cat: this: No such file or directory
cat: filename: No such file or directory
음... 아마 파일 이름이 띄어쓰기로 되어있어 읽어지지 않는 것 같긴 합니다!
이런 파일을 읽으려면 어떻게 해야할까요?
리눅스에서는 명령어를 실행할 때 옵션, 파일 이름 등 추가적인 정보를 줄 수 있습니다. 이런 것들을 인수라고 부르지요! cat 명령어 뒤에 오는 파일 이름을 인수로 볼 수 있습니다.
이런 인수들을 구분하기 위하여 '공백'을 사용합니다!
따라서 'spaces in this filename'은 4개의 파일로 인식하게 되어 cat 명령어가 제대로 실행되지 않는 것이지요!!
실제로 파일 2개를 만들어서 실험해본 결과, 공백으로 인수 2개를 주어 파일을 읽어보았더니 아래와 같은 결과가 나왔습니다.
moonsookang@MoonSooui-noteubug ~ % echo "Hello, My name is Test1" > file.txt
# "Hello, My name is Test1"을 화면에 출력하는 대신 file.txt라는 파일에 저장함.
moonsookang@MoonSooui-noteubug ~ % echo "Hello, My name is Test2" > file2.txt
moonsookang@MoonSooui-noteubug ~ % cat file.txt
Hello, My name is Test1
moonsookang@MoonSooui-noteubug ~ % cat file2.txt
Hello, My name is Test2
moonsookang@MoonSooui-noteubug ~ % cat file.txt file2.txt
Hello, My name is Test1
Hello, My name is Test2
리눅스에게 공백이 포함된 정보를 하나의 인수로 인식시키기 위해서는 큰따옴표("")를 사용합니다.
bandit2@bandit:~$ cat "spaces in this filename"
MNk8KNH3Usiio41PRUEoDFPqfxLPlSmx
정상적으로 파일의 내용을 읽어오는군요!
또 하나의 방법은 리눅스에게 공백이 파일 인수를 구별하는 '특수문자'가 아닌 '일반문자'로 인식하도록 이스케이프('\') 처리를 하는 것 입니다.
bandit2@bandit:~$ cat spaces\ in\ this\ filename
MNk8KNH3Usiio41PRUEoDFPqfxLPlSmx
마찬가지로 파일 내용을 읽어 오는 것을 확인할 수 있습니다.
오늘도 멋진 글이네요 😆