junior-ctf/tutorials/command_line.md
2019-05-17 12:20:43 +02:00

2.1 KiB

Introduction

The command line interface is run in a terminal (or prompt). It is the direct interface with your computer. There you are able to do the same things are you are able in a graphic interface such as visiting a folder, reading and writing files.

But the command line interface allows you access to a number of other programs which are really useful in a developer's every day life or while participating in CTFs. You should not be an expert, but with little knowledge of the command line you will already be able to do a number of things faster and quicker.

Terminals in Linux and OSX are quite similar, if you run Windows, things are a bit different.

Understanding paths

Paths are the base of the structure of your operating system. You have to think of it like a tree (there is even a command to show you the whole structure of your folders called tree -- try it out!).

For example:

home folder
| sub folder
|  | sub sub folder
|  |  file in sub sub folder.txt
| second sub folder

Your home folder (/home/your_username) is usually abreaviated by ~. So for example the "Documents" folder in your home folder is marked as ~/Documents. This is how the structure works for the example above:

home folder/sub folder/sub sub folder/file in sub sub folder.txt

Basic command line

  • List the files in the current folder: ls
  • See where you are: pwd
  • See who you are: whoami
  • Go in a folder: cd INSERT_HERE_THE_NAME_OF_YOUR_FOLDER
  • Go in the parent folder: cd ..
  • Go to your home directory: cd ~ or cd
  • Print a file in the terminal: cat THE_NAME_OF_YOUR_FILE
  • Copy a file: cp YOUR_FILE YOUR_DESTINATION

Run programs in command line

You can feel like a real hacker from movies while just using your terminal. So this means you can run program in the command line. Already the few examples above are small programs. To run a program you have to write the name of the program you want to run and options and then press "enter" to run it.

Many programs have a manual to explain how to use them, you can access it by using the --help or -h option. Try typing: cat --help and then press enter in your terminal.