CHAPTER 03
Linux and Command Line Basics
Updated: May 15, 2026
20 min read
# CHAPTER 3
Linux and Command Line Basics
1. Introduction
If you want to be a cybersecurity professional, the graphical user interface (GUI) is your enemy; the terminal is your best friend. The vast majority of web servers in the world run on Linux. Almost all penetration testing tools are designed specifically for the Linux command line. When you successfully exploit a server, you don't get a nice desktop with a mouse; you get a blinking cursor in a black box. In this chapter, we will build absolute fluency in the Linux command line. We will learn how to navigate the file system, manage user permissions, and master the core commands required for system administration and security auditing.2. Learning Objectives
By the end of this chapter, you will be able to:-
Navigate the Linux file system using terminal commands (
cd,ls,pwd).
-
Manipulate files and directories (
cp,mv,rm,mkdir).
-
Read and search file contents (
cat,grep,less).
-
Understand and modify Linux file permissions (
chmod,chown).
-
Elevate privileges safely using
sudo.
3. Beginner-Friendly Explanation
Imagine a massive library with no signs and no librarians.- Using a Mouse (GUI): Walking through the library, pulling out every book, looking at the cover, and putting it back until you find the right one.
-
Using the Terminal (CLI): Walking up to a computer in the lobby, typing
find book named "Security", and the computer instantly printing out exactly what aisle and shelf the book is on.
The terminal is simply a way to talk directly to the operating system's brain without having to wait for the computer to draw pretty pictures on the screen. It is infinitely faster and more powerful.
4. Basic Navigation Commands
Open the terminal in Kali Linux.-
Print Working Directory (
pwd): Tells you exactly where you are. (e.g.,/home/kali).
-
List (
ls): Shows the files in your current directory. Usels -lato see hidden files and file permissions.
-
Change Directory (
cd): Moves you around.
-
cd /etc(Moves to the/etcconfiguration folder).
-
cd ..(Moves up one folder).
-
cd ~(Moves to your home directory).
5. File Manipulation and Searching
-
Make Directory (
mkdir myfolder): Creates a new folder.
-
Copy (
cp file.txt /tmp/): Copies a file.
-
Move/Rename (
mv old.txt new.txt): Renames a file or moves it to a new location.
-
Remove (
rm file.txt): Deletes a file. Warning: There is no "Recycle Bin" in the terminal. If you typerm -rf /, it will destroy your entire operating system instantly.
Reading and Searching:
-
cat /etc/passwd: Dumps the entire contents of a file to the screen.
-
grep "root" /etc/passwd: Searches inside a file for a specific word. *This is the most powerful command in cybersecurity.*
6. Mini Project: Practice Linux Administration Tasks
Let's practice managing file permissions. Linux security is based on permissions: Read (r), Write (w), and Execute (x).
Step-by-Step Walkthrough:
-
1.
Create a script:
echo "echo Hello World" > script.sh
-
2.
Try to run the script:
./script.sh
-
3.
Look at the permissions:
ls -l script.sh
-rw-r--r--. Notice there is no 'x').*
- 4. Change the mode (chmod): Grant the user execute permissions.
bash
chmod +x script.sh
`
-
5.
Run it again:
./script.sh
*(It will output "Hello World" successfully).*
7. Real-World Scenarios
A junior system administrator was told to find a specific error message in a massive, 5-Gigabyte log file on a web server. They downloaded the file to their laptop and tried to open it in Microsoft Notepad. Notepad crashed instantly because the file was too large. A senior security engineer logged into the server via SSH and typed one command: grep "ERROR 500" /var/log/apache2/access.log. The terminal instantly extracted the exact 5 lines where the error occurred. Command-line proficiency turns impossible tasks into a five-second keystroke.
8. Best Practices
-
Tab Completion: Never type out long file paths. If you want to go to
/var/log/apache2, type cd /va, press the TAB key on your keyboard, and Linux will auto-complete the rest of the word. This prevents spelling mistakes and saves massive amounts of time.
-
The Up Arrow: Press the 'Up' arrow key to cycle through commands you previously typed so you don't have to type them again.
9. Security Recommendations
-
The Principle of Least Privilege (
sudo): You should never log in as the root user (the absolute administrator). If you accidentally run a malicious script as root, it can destroy the computer. Instead, log in as a standard user (like kali). When you absolutely need to do something administrative (like install software), type sudo before the command (e.g., sudo apt update). This temporarily grants you root power for that single command, and asks for your password as a safety check.
10. Troubleshooting Tips
-
Trapped in a program: If you run a command that takes too long, or you get trapped in a weird terminal screen, press
Ctrl + C. This sends a "Kill" signal to the terminal and forces whatever is running to immediately stop, giving you your blinking cursor back.
11. Exercises
-
1.
What does the
ls -la command do, and why is it more useful for security audits than just ls?
-
2.
Explain the purpose of the
sudo command. Why is using sudo considered safer than logging in directly as the root user?
12. FAQs
Q: Do I need to memorize every Linux command?
A: No. Nobody does. You just need to know how to read the manual. If you don't know how a command works, type man <command> (e.g., man nmap) to read the official instruction manual right in the terminal.
13. Interview Questions
-
Q: Describe the Linux file permission model (Read, Write, Execute). How would you use the
chmod command to ensure a bash script is executable only by the file's owner?
-
Q: In a post-exploitation scenario, you need to find all configuration files on a compromised Linux server that contain the word "password". Provide the command-line syntax utilizing
grep to achieve this.
14. Summary
In Chapter 3, we stripped away the Graphical User Interface and confronted the raw power of the Linux Terminal. We learned how to navigate the file hierarchy (cd, pwd), manipulate files securely (mv, cp), and powerfully parse massive datasets utilizing cat and grep. We demystified the Linux permission model (chmod), understanding that file execution is a privilege, not a default right. Finally, we embraced the defensive philosophy of sudo`, ensuring that administrative power is wielded deliberately. Fluency in these commands is the absolute prerequisite for operating security tools and auditing compromised servers.