Mastering Terminal Commands for Beginners

Whether you are in the beginning stages of your pentesting journey, a SOC analyst, incident responder, or threat analyst, at some point in your career, you will have to use your computer’s terminal.

The Terminal is an interface that allows an user to interact with the computer via the command line (CLI). As the name implies, here you can type commands to tell the computer exactly what to do. You can also combine an option, or multiple options, with a command to get more detailed information.

Users familiar with the command line consider it easier and faster to perform complex tasks. Kali Linux is one of the many Operating Systems (OS) that uses Terminal as its main CLI. I will use this OS for the following exercises.

Keep in mind that the commands may be different if you are on MacOS, Windows, or any other OS.

Where am I?

When you start digging within Terminal, you may go down so deep, you don’t know where you are. Think of the following command as your map: pwd. This command is short for Present Working Directory and will show you the path to where you are currently at.

List

If you have never opened the Terminal before it might be a good idea to first see what information you have available and where you can go. The ls command, or list, is perfect for this. It will show you a list of documents, folders, and any files available within your current path or selected file. The syntax looks like this: ls [-option] [file].

Note: only add [file] when you wish to see the contents of a specific file.

Change Directory

After using the ls command you might want to move to a different directory or go back to the previous one. To do so, you will need the cd command; short for change directory. This is the equivalent of double clicking on a file/folder to open it and see its content or clicking on a back arrow to go back to the previous page. The syntax looks like this: cd [new_folder] or to go back to the previous location use two periods like this: cd .. and press enter.

Directory

To create folders you need to use the mkdir command. This is short for make directory. Following the command add the name of the folder you wish to create. The syntax looks like this: mkdir [file_name].

.txt Files

Users can create .txt files within the Terminal using the touch command. The syntax looks like this: touch [new_file_name.txt].

Move or Rename

The move command is used to move files, or rename them: mv. See syntax for each scenario below.

Renaming File(s)/Folder(s)

mv [source_file_name] [destination_file_name]

Moving File(s)/Folder(s)

mv [source_file_name] [destination_path]

Delete

A user may want to delete a file that was created by mistake, accidentally downloaded, or maybe need to delete a malicious file. To delete files use the remove command, or rm command. The syntax looks like this: rm [file_name].

Note: use -r option to delete folder that have files inside: rm [file_name] -r

And..

You may be wondering if you can multitask when doing these commands and the answer is yes. Using you can tell the Terminal to create a file, and a folder, and move the file into the folder. To do so, use the && command.

Terminal Practice 1

Summary

Now that we have a better understanding of some of the basic Terminal commands we can go ahead and put it into practice. On this exercise we will create a .txt file as well as a directory to move the file into, and lastly, we’ll delete the folder from our computer.

Open up your terminal on Kali by simultenaously pressing ctrl + alt + t or you can find it by searching on your local applications list. Once you are in the Terminal you can list your folders and move into the Desktop folder using the commands below:

ls
cd Desktop
Figure shows how to display folders with ls command and navigating to Desktop using cd command.

Note: if you want to make sure you are on your Desktop folder type pwd on the terminal and it will output your current location.

Figure shows how to verify where you are using the pwd command.

From inside the Desktop folder we will create a .txt and name it practice using the touch command. Then we will use the mkdir command to create a folder named documents where we will keep this file. Finally, we will move the file inside the folder we just created.

touch practice.txt && mkdir documents && mv practice.txt documents
Figure shows how to create a file and a folder while simultenaously moving the file to inside a folder.

Note: if you want to verify your .txt file is inside the folder you can do so by navigating into the files folder and displaying them.

cd documents && ls

To delete the folder and its contents we will use the rm command. Make sure you are on the Desktop folder and use the command below to delete it. Remember that because the folder is not empty, you will need to use the -r option.

rm -r files
Figure shows how to delete a folder and its content.

Congratulations! You now have a basic understanding on how to use the Terminal. Today, I showed you how to create files and folders, move files to different locations, and how to delete folders. There is so much more that can be done with Terminal. Stay tuned to learn more about how to use Terminal.


Discover more from Cyber-Jot | Learn Cybersecurity & OSINT

Subscribe to get the latest posts sent to your email.

Leave a Reply

Proudly powered by WordPress | Theme: Baskerville 2 by Anders Noren.

Up ↑

Discover more from Cyber-Jot | Learn Cybersecurity & OSINT

Subscribe now to keep reading and get access to the full archive.

Continue reading