Cybersecurity Fundamentals, Part 2: The Linux Command Line, Terminal

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.


Kali Linux Terminal window
Kali Linux Terminal

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.


Terminal command `ls` and folders subsequently displayed
`ls` command in action.

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.


Results in Terminal of the command `man ls`
`man ls` results

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.


`cd Documents`, then `ls` to view the contents.

Extra Credit:

  • Let's say you want to move back from one directory to it's parent directory. In our example, moving up from Documents to Home. Look up the command `cd ..`.
  • Look up the difference between Absolute and Relative paths.
  • In our example, when we changed directories into Documents, it displayed a `~/Documents`. The tilda (~) represents the Home directory. Typing `cd ~` will return you to your home directory, and `cd /` will bring you further up to Root.

Other helpful commands and keys:

  • `ls`: List files in current directory
  • `man`: Load the instruction manual of a command. Eg. `man ls`
  • `ls -l`: List expanded details of files and their locations. `-l` is an argument added to a command.
  • `pwd`: Display present working directory
  • `cd`: Change directory.
  • `cd ..`: My back to the parent directory of the one you're currently in
  • `cd ~`: Change to highest parent directory
  • `cd /`: Change to root directory
  • `mkdir`: Make a new directory (AKA folder)
  • `touch`: Create a new file. Eg. `touch to-do-list.txt`
  • `whoami`: Display current user
  • `clear`: Delete previous terminal content
  • `tree`: Show file tree for current directory
  • `cp`: Copy
  • `mv`: Move
  • `rm`: Remove
  • Hot key - <ctrl + z>: Suspends current foreground process (not terminated)
  • Hot key - <ctrl + c>: Terminate current foreground process

Tips

  • Don't be shy to ask your favorite genAI chatbot like ChatGPT, Google Gemini, MS Copilot to provide lists of common commands, explain particular commands in detail, teach you vocabulary, etc. The chatbots are fairly accurate when it comes to most of this content. All that being said, don't forget to try using the `man` command first in order to get more comfortable reading Terminal based text and syntax.
  • If you want to install a Linux OS onto your own computer, consider using Ubuntu or Debian Linux distributions, as they are the most popular and thus have the most support and maintenance. Plenty of content on Google about how to set these up.
  • If you don't want to dual boot between Windows/Linux/Mac, look up how to setup a Virtual Machine (VM) like Hyper-V on Windows, then run an ISO of the Linux distribution through a VM.

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!



要查看或添加评论,请登录