![]() |
| Ethical Hacking |
🛡️ Ethical Hacking — Day 4
Command Line & Shell Fundamentals — Linux, Windows & macOS
⚠️ LEARNING PURPOSE ONLY: This tutorial is strictly for educational and defensive cybersecurity learning. Perform practical exercises only on systems, applications, networks, virtual machines, or labs that you own or have explicit permission to test. Do not use these commands to access, scan, exploit, or disrupt unauthorized systems.
Welcome to Day 4.
In Day 3, we learned about operating systems, users, permissions, processes, services, and environment variables. Today, we'll learn one of the most important skills for an ethical hacker:
Working effectively from the command line.
You'll practice equivalent concepts using:
🐧 Linux — Bash
🪟 Windows — PowerShell
🍎 macOS — Zsh
🎯 Day 4 Learning Objectives
By the end of today, you should be able to:
Navigate directories from the command line
Create, copy, move, and delete files
Read files from the terminal
Search files and text
Use pipes
Redirect command output
Combine commands
Understand command exit status
Work with environment variables
Perform basic system investigation
Understand the difference between Bash, Zsh, CMD, and PowerShell
1. What Is a Shell?
A shell is a command interpreter that allows you to interact with the operating system.
Instead of clicking:
File Manager → Folder → File
you can type:
cd folder
ls
cat file.txt
The general model is:
You
↓
Shell
↓
Operating System
↓
Hardware / Applications
2. Shells You'll Encounter
🐧 Linux
Common shells include:
Bash
Zsh
Fish
Bash is extremely common in Linux environments.
🍎 macOS
Modern macOS uses Zsh as its default interactive shell.
You can check yours with:
echo $SHELL
🪟 Windows
Windows provides:
Command Prompt (
cmd.exe)PowerShell
For cybersecurity learning, PowerShell is particularly important because it provides extensive access to Windows administration and system information.
3. Your First Command-Line Rule
Don't blindly copy commands.
For every command, ask:
What does this command do?
Then:
What system or files will it affect?
And finally:
What output should I expect?
This habit is extremely important in cybersecurity.
📁 4. Navigation
🐧 Linux
Show current directory:
pwd
List files:
ls
Detailed listing:
ls -la
Change directory:
cd /tmp
Go home:
cd ~
Go one level up:
cd ..
🍎 macOS
The basic navigation commands are essentially the same:
pwd
ls -la
cd /tmp
cd ~
cd ..
🪟 Windows PowerShell
Current directory:
Get-Location
List files:
Get-ChildItem
Change directory:
Set-Location $env:TEMP
Go home:
Set-Location $HOME
Go one level up:
cd ..
PowerShell also provides familiar aliases:
pwd
ls
cd
However, learning the actual PowerShell cmdlet names is useful.
🧪 Practical 1 — Create Your Training Environment
We're going to create a directory that will be used throughout today's exercises.
🐧 Linux
mkdir ethical-hacking-day4
cd ethical-hacking-day4
pwd
🍎 macOS
mkdir ethical-hacking-day4
cd ethical-hacking-day4
pwd
🪟 Windows PowerShell
New-Item -ItemType Directory ethical-hacking-day4
Set-Location ethical-hacking-day4
Get-Location
You should now be inside your new training directory.
📄 5. Creating Files
Linux / macOS
Create an empty file:
touch notes.txt
Create another:
touch commands.txt
Check:
ls -l
Windows PowerShell
New-Item notes.txt
New-Item commands.txt
Check:
Get-ChildItem
✍️ 6. Writing Text to a File
Linux / macOS
Run:
echo "Ethical hacking is authorized security testing." > notes.txt
View it:
cat notes.txt
Add another line:
echo "Practice only in authorized environments." >> notes.txt
View:
cat notes.txt
Important difference
> Replace/create output
>> Append output
Windows PowerShell
"Ethical hacking is authorized security testing." | Set-Content notes.txt
View:
Get-Content notes.txt
Append:
"Practice only in authorized environments." | Add-Content notes.txt
View:
Get-Content notes.txt
📖 7. Reading Files
Linux / macOS
cat notes.txt
For longer files:
less notes.txt
You can exit less using:
q
Show the first lines:
head notes.txt
Show the last lines:
tail notes.txt
Windows PowerShell
Get-Content notes.txt
First lines:
Get-Content notes.txt -TotalCount 10
Last lines:
Get-Content notes.txt -Tail 10
📋 8. Copying Files
Linux / macOS
cp notes.txt notes-backup.txt
Check:
ls -l
Windows PowerShell
Copy-Item notes.txt notes-backup.txt
Check:
Get-ChildItem
🚚 9. Moving / Renaming Files
Linux / macOS
Rename:
mv notes-backup.txt backup.txt
Windows PowerShell
Rename-Item notes-backup.txt backup.txt
🗑️ 10. Deleting Files
Be careful with deletion commands.
Linux / macOS
rm backup.txt
Windows PowerShell
Remove-Item backup.txt
Then verify:
Linux/macOS:
ls
Windows:
Get-ChildItem
⚠️ Safety rule: Never experiment with
rm,Remove-Item, or recursive deletion commands on directories you don't understand. For this course, only use them inside your own training directory.
🔎 11. Searching for Files
Searching is an essential cybersecurity skill.
🐧 Linux
Find a file in your current training directory:
find . -name "notes.txt"
🍎 macOS
find . -name "notes.txt"
🪟 Windows PowerShell
Get-ChildItem -Path . -Filter notes.txt -Recurse
This becomes useful later when investigating large filesystems.
🔍 12. Searching Text
Suppose notes.txt contains:
Ethical hacking is authorized security testing.
Practice only in authorized environments.
Linux / macOS
Search for:
grep "authorized" notes.txt
You should see the matching line.
Case-insensitive search:
grep -i "AUTHORIZED" notes.txt
Windows PowerShell
Select-String -Path notes.txt -Pattern "authorized"
Case-insensitive matching is generally supported by default in PowerShell's string comparison behavior.
🔗 13. Pipes — One of the Most Important Concepts
A pipe sends the output of one command into another command.
The symbol is:
|
Conceptually:
Command A
↓
|
↓
Command B
For example:
Linux / macOS
ps aux | grep ssh
This means:
ps aux
↓
produce process list
↓
grep ssh
↓
show matching lines
On your own system, there may be no matching process—and that's perfectly fine.
Windows PowerShell
Get-Process | Where-Object {$_.ProcessName -like "*chrome*"}
The first command produces process objects.
The second filters them.
This is one of the major strengths of PowerShell.
📤 14. Output Redirection
You can save command output to a file.
Linux / macOS
uname -a > system-info.txt
Then:
cat system-info.txt
Append another command:
whoami >> system-info.txt
Then:
cat system-info.txt
Windows PowerShell
systeminfo | Out-File system-info.txt
Then:
Get-Content system-info.txt
You can append:
whoami | Out-File system-info.txt -Append
🔢 15. Command Exit Status
Commands can return a status indicating whether they succeeded.
This is important when writing scripts.
Linux / macOS
Run:
true
echo $?
You should normally see:
0
0 conventionally means success.
Now:
false
echo $?
You'll normally get a non-zero status.
Windows PowerShell
PowerShell provides:
$?
For example:
Write-Output "Success"
$?
You can also inspect:
$LASTEXITCODE
after running native executables that return an exit code.
🌱 16. Environment Variables
We introduced these yesterday.
Today let's use them.
Linux / macOS
echo $HOME
echo $PATH
Current user:
echo $USER
List variables:
env
Windows PowerShell
$env:USERPROFILE
$env:Path
Username:
$env:USERNAME
List environment variables:
Get-ChildItem Env:
🖥️ 17. System Information
A security professional needs to know what operating system they're dealing with.
Linux
uname -a
Distribution information may be available with:
cat /etc/os-release
macOS
sw_vers
Kernel/system information:
uname -a
Windows
PowerShell:
Get-ComputerInfo | Select-Object WindowsProductName, WindowsVersion
You can also run:
systeminfo
👤 18. User Information
Linux / macOS
whoami
id
Windows
whoami
whoami /groups
The second command can help you understand Windows group membership.
⚙️ 19. Process Investigation
Today we're not attacking anything; we're simply learning to inspect your own computer.
Linux
ps aux
Filter:
ps aux | grep -i ssh
macOS
ps aux
Filter:
ps aux | grep -i ssh
Windows
Get-Process
Filter:
Get-Process | Where-Object {$_.ProcessName -like "*ssh*"}
🌐 20. Network Information
We covered networking on Day 2.
Today let's combine command-line skills with networking.
Linux
ip addr
ip route
macOS
ifconfig
route -n get default
Windows
ipconfig
route print
These commands are useful for understanding your own system's network configuration.
🧪 Day 4 Main Practical Lab
Now let's combine everything.
Create a file called:
day4-system-report.txt
and collect basic information about your own computer.
🐧 Linux
echo "=== SYSTEM ===" > day4-system-report.txt
uname -a >> day4-system-report.txt
echo "=== USER ===" >> day4-system-report.txt
whoami >> day4-system-report.txt
echo "=== DIRECTORY ===" >> day4-system-report.txt
pwd >> day4-system-report.txt
echo "=== NETWORK ===" >> day4-system-report.txt
ip addr >> day4-system-report.txt
echo "=== PROCESSES ===" >> day4-system-report.txt
ps aux >> day4-system-report.txt
View the report:
less day4-system-report.txt
Press q to exit.
🍎 macOS
echo "=== SYSTEM ===" > day4-system-report.txt
sw_vers >> day4-system-report.txt
echo "=== USER ===" >> day4-system-report.txt
whoami >> day4-system-report.txt
echo "=== DIRECTORY ===" >> day4-system-report.txt
pwd >> day4-system-report.txt
echo "=== NETWORK ===" >> day4-system-report.txt
ifconfig >> day4-system-report.txt
echo "=== PROCESSES ===" >> day4-system-report.txt
ps aux >> day4-system-report.txt
View:
less day4-system-report.txt
🪟 Windows PowerShell
"=== SYSTEM ===" | Set-Content day4-system-report.txt
Get-ComputerInfo | Select-Object WindowsProductName, WindowsVersion | Out-File day4-system-report.txt -Append
"=== USER ===" | Out-File day4-system-report.txt -Append
whoami | Out-File day4-system-report.txt -Append
"=== DIRECTORY ===" | Out-File day4-system-report.txt -Append
Get-Location | Out-File day4-system-report.txt -Append
"=== NETWORK ===" | Out-File day4-system-report.txt -Append
ipconfig | Out-File day4-system-report.txt -Append
"=== PROCESSES ===" | Out-File day4-system-report.txt -Append
Get-Process | Out-File day4-system-report.txt -Append
View:
Get-Content day4-system-report.txt
🧠 Understanding the Lab
You've just combined several important security concepts:
System Information
↓
User Information
↓
Filesystem
↓
Network Configuration
↓
Running Processes
↓
Saved Evidence
This basic workflow is similar to what security professionals do during system assessment—but professional testing requires clearly defined scope and authorization.
🛡️ Command-Line Security Mindset
Don't think of commands as things you simply memorize.
Think of them as questions you're asking the operating system.
For example:
whoami
means:
"Who am I on this system?"
ps aux
means:
"What processes are running?"
ip addr
means:
"What network interfaces and addresses does this system have?"
ls -la
means:
"What files exist here, including hidden files, and what permissions do they have?"
This mindset will become very useful as we progress into security testing.
🧪 Day 4 Assignment
Answer the following:
1.
What is a shell?
2.
What is the difference between Bash and PowerShell?
3.
What does pwd do?
4.
What does ls -la do?
5.
What is the difference between > and >>?
6.
What does the | symbol do?
7.
What does grep do?
8.
What is the PowerShell equivalent concept for searching/filtering command output?
9.
What does whoami tell you?
10.
Why is understanding command-line tools important for an ethical hacker?
🏆 Day 4 Challenge
On your own computer, complete the following:
Linux
pwd
ls -la
whoami
uname -a
ps aux
ip addr
Windows
Get-Location
Get-ChildItem
whoami
Get-ComputerInfo | Select-Object WindowsProductName, WindowsVersion
Get-Process
ipconfig
macOS
pwd
ls -la
whoami
sw_vers
ps aux
ifconfig
Then explain what each command tells you.
Bonus
Create a report file containing:
Operating System
Current User
Current Directory
Network Information
Running Processes
⚠️ Ethical Hacking Reminder
LEARNING PURPOSE ONLY: Everything in this lesson is intended for educational and authorized security practice. Commands that inspect files, processes, users, permissions, or networking should be run only on systems you own or are explicitly authorized to administer/test. Never use command-line skills to access or interfere with unauthorized systems.
✅ Day 4 Summary
Today you learned:
What a shell is
Bash and Zsh fundamentals
PowerShell fundamentals
Directory navigation
File creation
File reading
Copying and moving files
File deletion
Searching files
Searching text
Pipes
Output redirection
Exit status
Environment variables
System information
User information
Process investigation
Network information
Cross-platform command-line workflows
The biggest lesson today is:
A strong ethical hacker doesn't just know tools—they understand the operating system underneath those tools.
🔜 Day 5 — Networking Deep Dive
Tomorrow we'll go deeper into networking:
🌐 IP → MAC → ARP → Ports → TCP → UDP → DNS
We'll cover:
IPv4 addressing and CIDR
Subnet basics
ARP
ICMP
TCP three-way handshake
UDP communication
Common ports
DNS resolution
Network troubleshooting
Linux, Windows & macOS practical commands
Safe packet/network observation on your own system
🔐 Learn → Practice → Understand → Secure.

No comments:
Post a Comment