Advertisement

HexaGuard: Mastering the Art of Digital Shadows

hands on practice on cmd powershell and bash

 

🔹 Task 1: Get System Information

📌 Goal: Check OS details using Bash, PowerShell, and CMD.

Bash (Linux/macOS) 🐧

bash

uname -a lsb_release -a # For Debian-based systems cat /etc/os-release # More detailed info

PowerShell (Windows) 🔵

powershell

Get-ComputerInfo | Select-Object OsName, WindowsVersion, OsArchitecture, OsBuildNumber

CMD (Windows)

cmd

systeminfo | findstr /B /C:"OS Name" /C:"OS Version"

🔹 Task 2: List All Files in a Directory

📌 Goal: Display files in a specific directory.

Bash 🐧

bash

ls -l

PowerShell 🔵

powershell

Get-ChildItem

CMD

cmd

dir

🔹 Task 3: Create & Write to a File

📌 Goal: Create a new file and add text to it.

Bash 🐧

bash

echo "Hello from Bash!" > myfile.txt cat myfile.txt

PowerShell 🔵

powershell

"Hello from PowerShell!" | Out-File -FilePath myfile.txt Get-Content myfile.txt

CMD

cmd

echo Hello from CMD! > myfile.txt type myfile.txt

🔹 Task 4: Find a Running Process

📌 Goal: Search for a process (e.g., chrome) running on your system.

Bash 🐧

bash

ps aux | grep chrome

PowerShell 🔵

powershell

Get-Process | Where-Object { $_.ProcessName -match "chrome" }

CMD

cmd

tasklist | findstr chrome

🔹 Task 5: Kill a Process

📌 Goal: Terminate a running process.

Bash 🐧

bash

kill -9 <PID> # Replace <PID> with the actual process ID

PowerShell 🔵

powershell

Stop-Process -Name "chrome" -Force

CMD

cmd

taskkill /IM chrome.exe /F

💥 Bonus Challenge: Create a Simple Script

📌 Goal: Automate file creation and listing.

Bash Script (save as script.sh)

bash

#!/bin/bash echo "Creating a file..." echo "Hello, Bash!" > myscriptfile.txt echo "File created. Listing files:" ls -l

Run it:

bash

chmod +x script.sh ./script.sh

PowerShell Script (save as script.ps1)

powershell

Write-Output "Creating a file..." "Hello, PowerShell!" | Out-File myscriptfile.txt Write-Output "File created. Listing files:" Get-ChildItem

Run it:

powershell

powershell -ExecutionPolicy Bypass -File script.ps1

Batch Script (save as script.bat)

cmd

@echo off echo Creating a file... echo Hello, CMD! > myscriptfile.txt echo File created. Listing files: dir

Run it:

cmd

script.bat


Post a Comment

0 Comments