Cybersecurity Fundamentals, Part 2: The Linux Command Line, Terminal
Thanks to my dad being a computer geek when I was a kid, the first book I studied in my coding journey was a Linux Magazine he gifted me, containing article on Linux 101 basics: How to setup a Linux OS, navigate the GUI, and work with the Command Line/Terminal.
I do believe that this start was the bedrock of my ability to navigate the Linux challenges presented in my current cybersecurity bootcamp. If you're thinking about getting into coding and/or cybersec, consider putting Linux and the Command Line at the top of your to-do list.
Note: Code to type in will be indicated by code blocks, the bits of text below within the darker, rounded containers. In-line code will be indicated by ticks ``, eg. `cd Documents`.
Note2: Hyperlinks within the article will redirect you to external websites to learn more about those linked items.
Linux Terminal
Whether it's Linux, Windows, or Mac you're working with, each of them have their respective Command Lines. In Linux: "Terminal". Windows: "Command Prompt" or "PowerShell". Mac: also "Terminal". All commonly known as Command Line. While most of the Terminal commands can be executed via the Graphical User Interface (AKA GUI AKA "gooey"), it's important to become proficient in using the Terminal as many systems don't have a GUI, like headless servers.
In a Linux Operating System (OS) or subsequent Distribution (aka Distro), in order to open Terminal, type:
ctrl+alt+t
This will open a Terminal, a simple looking text-based program with an active cursor awaiting your command. You can also find the Terminal icon on your GUI, but it's a good idea to using text-based hotkeys and commands for both efficiency and foundational learning.
In the above image, you'll see `(kali-kali)-[~]`. In order, this indicates the host system I'm using, Kali Linux, the current user (also "kali") and the `~` represents my current location: the home directory.
Commands
Commands are the actions you type into Terminal in order to execute your desired result.
Some of my commonly used commands are `ls`, `man`, `cd`, `pwd`, `head`, `tail`, and `cat`.
The most frequent command I use, especially when starting out on a new Terminal instance, is the `list` command, shortened to:
ls
After typing `ls`, press <enter>. The `list` command will display the contents of the Terminal's current Directory (AKA folder) location.
Do you want to know more about what the `ls` command can do? Use the `manual` command. The man command is short for "instruction manual". Before internet-based technical documentation was available, manuals like this were the first source one would dig into in order to learn more about the command's capabilities.
Try it: type `man`, followed by whichever command you want to learn more about:
man ls
Press <enter> to execute the command. You will see a wall of text open up with sections like NAME, SYNOPSIS, and DESCRIPTION. The syntax can be overwhelming at first, so it's important to slow down and digest what you're reading.
To exit the manual, type <q>.
So we've explored our current directory with `ls`. The default starting directory (~) is going to be Home. If you've ended up elsewhere, you can always move back to home with `cd ~`. From the Home directory, let's say you want to move into another folder, like Documents. In a GUI, you'd simply double-click a folder like Documents in order to access it. In Terminal, you will use the command line to access the folder and few its contents. This is `cd`, short for "change directory".
cd Documents
At this point, you may not see any list of files or directories displayed, but check the image below, the current directory is referenced as `~/Documents`, indicating that you've moved into that folder, with the parent directory being Home, or ~. Again, enter command `ls` to list out any files and directories within Documents.
Extra Credit:
Other helpful commands and keys:
Tips
For this article, I was using a Kali Linux distro via Hyper-V on my Windows rig, which was setup using: https://www.kali.org/docs/virtualization/install-hyper-v-guest-vm/.
Conclusion
It's helpful to imagine learning Terminal is like learning a new video game and going through the initial tutorial. At first, they teach you how to navigate and look around your new world. That's what we've done here. I've provided some extra steps in the previous two sections so that you can learn how to manipulate and further explore the Terminal.
If you have spotted any errors in the above content, please comment and let me know!
Happy Hacking!