Windows Command Line
- Basic System Information
- Network Troubleshooting
- File and Disk Management
- Task and Process Management
- Conclusion
Windows PowerShell
- What Is PowerShell
- PowerShell Basics
- Navigating the File System and Working with Files
- Piping, Filtering, and Sorting Data
- System and Network Information
- Real-Time System Analysis
- Scripting
Linux Shells
- Introduction to Linux Shells
- How To Interact With a Shell?
- Types of Linux Shells
- Shell Scripting and Components
- The Locker Script
📝 Notes
Windows Command Line
Basic System Information
- command
set,PATH= C:\>set ALLUSERSPROFILE=C:\ProgramDataC:\>systeminfomore,driverquery,driverquery | more
Network Troubleshooting
C:\>ipconfigC:\ipconfig /allC:\>ping target_nameC:\>tracert example.com- time-to-live (TTL)
C:\>nslookup example.comC:\>netstat-adisplays all established connections and listening ports-bshows the program associated with each listening port and established connection-oreveals the process ID (PID) associated with the connection-nuses a numerical form for addresses and port numbers
sshd.exeC:\>netstat -abon
File and Disk Management
cd- current drive and directorydir- child directoriesdir /a- displays hidden and system files as welldir /s- displays files in the current directory and all subdirectories.C:\Users\ibuv4r.k>tree- visually represent the child directories and subdirectoriesdel- deletes a file (del *.png)copy- copies a file to a new location (*.txt)move- oves a file to a new locationtype- displays the contents of a text filemore- shows a file’s content one page at a timermdir- delete a folder
Task and Process Management
tasklisttaskkill/PID (pid)tasklist/FI (filter)
Conclusion
chkdsk- checks the file system and disk for errors, helping identify bad sectors or corrupt filesdriverquerysfc /scannow- scans and repairs corrupted system files
Windows PowerShell
What Is PowerShell
From the official Microsoft page: “PowerShell is a cross-platform task automation solution made up of
- a command-line shell,
- a scripting language, and
- a configuration management framework.
CMD vs PowerShell: CMD is text-based (like copy, echo). PowerShell returns objects (e.g., Get-ChildItem, Write-Output)
PowerShell Basics
Get-Content(read file content) – similar to type in CMD and cat in Linux.Set-Location(alias: cd) changes the current working directory, similar to cd in other shells. It’s useful when scripting or navigating file systems in PowerShell.Get-HelpRun the Get-Help core cmdlet to invoke a built-in help system.Get-Commandlists all available commands (including cmdlets, functions, aliases, etc.). It helps discover what commands are available and how to use them.cmdlet(pronounced “command-let”)
Navigating the File System and Working with Files
Get-ChildItem(ls,dir): Lists the contents of a directory. You can use it to see files and subfolders.Set-Location(cd): Changes the current working directory.New-Item: Creates a new item, such as a file or folder.Remove-Item(rm,del): Deletes files or folders.Get-Content(cat,type): Displays the content of a file.
Piping, Filtering, and Sorting Data
- PowerShell uses piping (
|) -Where-Object Get-Process | Where-Object { $_.CPU -gt 100 }Get-ChildItem | Select-Object Name, Length
comparison operators
| Operator | Meaning | Example |
|---|---|---|
-eq |
Equal to | $_ -eq 10 |
-ne |
Not equal to | $_ -ne 10 |
-gt |
Greater than | $_ -gt 5 |
-ge |
Greater than or equal to | $_ -ge 5 |
-lt |
Less than | $_ -lt 20 |
-le |
Less than or equal to | $_ -le 20 |
Common Commands
Sort-ObjectGet-Process | Sort-Object CPUWhere-ObjectGet-Process | Where-Object { $_.CPU -gt 100 }Select-ObjectGet-Process | Select-Object Name, CPU
System and Network Information
-
Get-ComputerInfo- retrieves a comprehensive set of system details, including OS version, architecture, BIOS, and more Useful for checking OS, hardware specs, and system configuration -
Get-NetIPConfiguration- displays details about network interfaces, such as IP address, gateway, and DNS settings. Great for troubleshooting network settings or viewing adapter info. -
Get-LocalUser- lists all local user accounts on the machine. Useful for auditing user accounts or managing local users.
Real-Time System Analysis
Get-Process - displays all currently running processes on the system
Useful for identifying resource usage and active programs.
Get-Service - lists all services, including their status (Running, Stopped, etc.)
Helpful for checking or managing Windows services.
Get-NetTCPConnection - shows active TCP connections, including local/remote IP addresses and ports
Essential for network diagnostics, identifying open ports, or spotting suspicious connections.
Scripting
Invoke-Command -ComputerName RemotePC -ScriptBlock {Get-Service}
This command executes Get-Service on a remote computer named RemotePC. It returns a list of services running (or stopped) on that machine.
Linux Shells
Introduction to Linux Shells
- A Linux shell is a command-line interface that allows users to interact with the operating system by entering text-based commands. Common shells like Bash, Zsh, and Fish enable automation, scripting, and deeper control over system operations.
How To Interact With a Shell?
- Most Linux distributions use Bash (Bourne Again Shell) as their default shell.
pwd- Current working directorycd- Change Directoryls- List directory contentscat- Displaying file contentsgrep- Searching a word in file
Types of Linux Shells
echo $SHELL
# command in Linux displays the default login shell for the current user
cat /etc/shells
# available shells in Linux
chsh -s /usr/bin/zsh
# permanently change your default shell (zsh)
- Bourne Again Shell (Bash) - default Shell in most Linux distributions
- Friendly Interactive Shell (Fish) - is known for its out-of-the-box usability, autosuggestions, syntax highlighting, and easy scripting without needing configuration.
- Z Shell (Zsh) - is powerful and highly customizable, often used with frameworks like Oh My Zsh, and is popular for its advanced features like better tab completion, globbing, and prompt customization.
Shell Scripting and Components
Key Components of a Shell Script:
- Shell scripting is a way to automate tasks in Unix-like systems by writing a series of commands in a script file, typically using shells like Bash, Zsh, or Fish.
- Shebang (
#!/bin/bash) – Tells the system which interpreter to use. -
- Comments (
#) – Explain what the script or specific lines do.
- Comments (
- Variables – Store and reuse values.
Defining the Interpreter
# This script solution was part of a TryHackMe room (Linux Shells)
# I did not write it myself — it's included here for reference and learning purposes.
# Defining the Interpreter
#!/bin/bash
echo "Please enter your name first:"
read name
if [ "$name" = "Stewart" ]; then
echo "Welcome Stewart! Here is the secret: THM_Script"
else
echo "Sorry! You are not authorized to access the secret."
fi
The Locker Script
A user has a locker in a bank. To secure the locker, we have to have a script in place that verifies the user before opening it. When executed, the script should ask the user for their name, company name, and PIN. If the user enters the following details, they should be allowed to enter, or else they should be denied access.
- Username: John
- Company name: Tryhackme
- PIN: 7385
# This script solution was part of a TryHackMe room (Linux Shells)
# I did not write it myself — it's included here for reference and learning purposes.
#!/bin/bash
# Prompting for user input
echo "Enter your Username:"
read username
echo "Enter your Company name:"
read companyname
echo "Enter your PIN:"
read -s pin # -s = silent input (not shown in terminal)
# Checking credentials
if [[ "$username" == "John" && "$companyname" == "Tryhackme" && "$pin" == "7385" ]]; then
echo "Authentication Successful. You can now access your locker, John."
else
echo "Authentication Denied!!"
fi
🐧 Conclusions
This summary explains how to use command-line tools in Windows (CMD and PowerShell) and Linux. In Windows CMD, you can check system info, manage files, and fix network issues. PowerShell offers more advanced features like object-based commands, filtering, and scripting. In Linux, shells like Bash let you control the system, manage files, and write simple scripts for automation.