This is a quick crash course on some of the basic Linux commands to enable you to use the terminal. We will be using a Kali Virtual Machine for this (for a guide on how to set up a VM, see my earlier posts on the topic)

The first thing you should know about is the prompt. By default the prompt tells you the current signed-in user, the hostname of the computer, and the current directory (We’ll discuss this further later). On Kali it will look like this:

image

It is formatted as ‘user@hostname:dir$’

This is a little confusing as by default both the username and hostname is ‘Kali’, but it is telling us we are signed in as ‘Kali’, the hostname is ‘Kali’, and the ‘~’ tells us we are in our current home directory.

The first command is “ls”. This command lists all the files and directories in the current directory (’directory’ is a synonym to what are commonly referred to as ‘folders’ in the windows GUI). A standard home directory will look something like this:

image

We use the command ‘cd’ to Change Directory. Let’s change to the ‘Documents’ dir with the command ‘cd Documents’. You should have noticed how the last part of the prompt has changed to ~/Documents. If we use ‘ls’ we should see that nothing happens.

image

This is because the current directory is empty. Many commands have extra options called ‘flags’ which allow you to change how the command runs. One of the flags for ‘ls’ is ‘-a’, which outputs everything in the current directory including hidden documents and directories. To use these options we type the command, and then the flag.

image
Here you can see there are actually two directories in ~/Documents/, these being ‘.’ and ‘..’. In Linux, the ‘.’ directory is the current directory, and ‘..’ is the directory above it. We can ‘cd’ to these directories like any other.
image
As you can see, ‘cd .’ didn’t do anything because we were trying to change to the directory we were already in, but ‘cd ..’ took us to our home directory. It’s looking a bit empty, so let’s learn how to create, see, and edit files. To create an empty file, we use the command ‘touch [file name]’, so to create a file called ‘hello.txt’ we use the command ‘touch hello.txt’. Let’s cd back to Documents and then try creating a new file.
image
hello.txt has been created. To view files in the terminal, we use the command ‘cat’ (so called because of it’s ability to con_cat_enate files).
image
Nothing happened because the file was empty, so now we can use a text editor to edit the file. Linux comes preloaded with some text editors. Personally I prefer Nano but there are others to choose from. After typing ‘nano hello.txt’, nano opens the file like this:
image
Feel free to type whatever you want here.
image
To exit nano we type Control X:
image
then y:
image
and then enter:
image
Now if we type ‘cat hello.txt’, it will output what we wrote.
image
To remove files, we can use the ‘rm’ command, with the name of the file to remove:
image
To create directories, we use the ‘mkdir [directory name]’ command, and we can use rm with the ‘-rf’ flag to remove empty directories. You have now learned the beginning of how to navigate around directories and files with a Linux terminal. There is a lot more but that can be learned over time. This was just a quick crash course. I would advise you play around the terminal and learn for yourself. The terminal may look imposing but it is essentially just what you would do on the user interface. Ubuntu has a good tutorial on how to use the terminal