🐂 🆚 ✴️ Everyday terminal commands used in GNU and their PowerShell equivalents.
In the world of task automation, mastering the command line is an essential skill. Whether using traditional GNU commands or navigating the Windows ecosystem with the powerful PowerShell, knowing the right tools can transform your productivity.
In this post, we’ll compare 50 GNU commands with their PowerShell equivalents.
💻 01. Delete a Directory Recursively
🐂 GNU
rm -rf /home/$USER/folder
✴️ PowerShell
Remove-Item -Path "C:\folder" -Recurse -Force
💻 02. Get the Name of a Running Process
🐂 GNU
ps aux | grep apache2 # httpd
systemd:
systemctl status apache2
✴️ PowerShell
Get-Service | Where-Object { $_.DisplayName -like "*Apache*" }
💻 03. Stop a Service
sudo kill -9 $(pidof apache2) # httpd
systemd:
sudo systemctl stop apache2
✴️ PowerShell
Stop-Service -Name "Apache2.4"
💻 04. Remove an Environment Variable
🐂 GNU
unset VARIABLE_NAME
✴️ PowerShell C:\App\bin
# Get the current value of the system Path environment variable
$envPath = [Environment]::GetEnvironmentVariable("Path", [EnvironmentVariableTarget]::Machine)
# Split paths into an array
$paths = $envPath -split ';'
# Filter to remove the unwanted path
$newPaths = $paths | Where-Object { $_ -ne "C:\App\bin" }
# Rebuild the Path environment variable (without the unwanted path)
$newPathString = ($newPaths -join ';').TrimEnd(';')
# Update the system environment variable
[Environment]::SetEnvironmentVariable("Path", $newPathString, [EnvironmentVariableTarget]::Machine)
💻 05. Check if a Command Exists
🐂 GNU
which mycommand
✴️ PowerShell
Get-Command mycommand
💻 06. Create a Folder/Directory
🐂 GNU
mkdir my-project
✴️ PowerShell
New-Item -ItemType Directory "MyProject"
💻 07. Create a Folder/Directory Recursively
🐂 GNU
mkdir -p my-project/folder/new
✴️ PowerShell
New-Item -Path "C:/MyProject/folder/new" -ItemType Directory
💻 08. Move a Folder/Directory
🐂 GNU
mv folder new/path/
💻 PowerShell
Move-Item -Path "folder" -Destination "C:\new\path\"
💻 09. Enter a Folder/Directory
🐂 GNU
cd folder/
✴️ PowerShell
Set-Location folder
💻 10. Copy Files and Directories
🐂 GNU
cp file path/to/dest
cp -r folder/ path/to/dest
✴️ PowerShell
Copy-Item file path\to\dest
Copy-Item folder\ -Recurse -Destination path\to\dest
💻 11. Get the Home Directory and/or Username
🐂 GNU
$HOME
# echo $HOME
$USER
# echo $USER
✴️ PowerShell
$env:USERPROFILE
# Write-Host $env:USERPROFILE
$env:USERNAME
# Write-Host $env:USERNAME
💻 12. List Files and Directories
🐂 GNU
ls -la
✴️ PowerShell
Get-ChildItem -Force
💻 13. Display Text File Content
🐂 GNU
cat file.txt
✴️ PowerShell
Get-Content file.txt
💻 14. Search for Text Inside Files
🐂 GNU
grep "term" file.txt
✴️ PowerShell
Select-String -Pattern "term" -Path file.txt
💻 15. Show Disk Usage
🐂 GNU
df -h
✴️ PowerShell
Get-PSDrive -PSProvider FileSystem
💻 16. Check Memory Usage
🐂 GNU
free -h
✴️ PowerShell
Get-CimInstance Win32_OperatingSystem | Select-Object TotalVisibleMemorySize,FreePhysicalMemory
💻 17. Display Environment Variables
🐂 GNU
printenv
✴️ PowerShell
Get-ChildItem Env:
💻 18. Rename File/Directory
🐂 GNU
mv oldname newname
✴️ PowerShell
Rename-Item -Path oldname -NewName newname
💻 19. Run Command as Administrator/Root
🐂 GNU
sudo command
✴️ PowerShell (run shell as admin)
Start-Process powershell -Verb runAs
💻 20. Check Network/Interfaces
🐂 GNU
ip addr show
✴️ PowerShell
Get-NetIPAddress
💻 21. Create an Environment Variable
Example for Terlang:
C:\Program Files\Terlang\bin
(Windows) and${HOME}/.local/terlang/bin/
(GNU)
🐂 GNU
export PATH="${PATH}:${HOME}/.local/terlang/bin/"
✴️ PowerShell
[System.Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\Program Files\Terlang\bin", [System.EnvironmentVariableTarget]::Machine)
💻 22. Display Last Lines of a File (tail)
🐂 GNU
tail -n 20 file.log
✴️ PowerShell
Get-Content file.log -Tail 20
💻 23. Monitor Processes in Real-Time (top)
🐂 GNU
top
✴️ PowerShell
Get-Process | Sort-Object CPU -Descending | Select-Object -First 10
(not real-time, but shows a snapshot of top CPU-consuming processes)
💻 24. Find and Kill a Process by Name
🐂 GNU
pkill -f process
✴️ PowerShell
Get-Process -Name process | Stop-Process -Force
💻 25. Monitor File Changes (tail -f)
🐂 GNU
tail -f file.log
✴️ PowerShell
Get-Content file.log -Wait
💻 26. Compress Files (tar gzip)
🐂 GNU
tar -czvf archive.tar.gz folder/
✴️ PowerShell
Compress-Archive -Path folder\* -DestinationPath archive.zip
💻 27. Extract Zip File
🐂 GNU
unzip archive.zip
✴️ PowerShell
Expand-Archive -Path archive.zip -DestinationPath destination\
💻 28. View Specific Environment Variables
🐂 GNU
echo $VARIABLE
✴️ PowerShell
$env:VARIABLE
💻 29. Set Environment Variable for Current Session
🐂 GNU
export VARIABLE=value
✴️ PowerShell
$env:VARIABLE="value"
💻 30. Display System Information (kernel, OS)
🐂 GNU
uname -a
✴️ PowerShell
Get-CimInstance Win32_OperatingSystem | Select-Object Caption, Version, OSArchitecture
💻 31. Check Current Date and Time
🐂 GNU
date
✴️ PowerShell
Get-Date
💻 32. Show Logged-In Users
🐂 GNU
who
✴️ PowerShell
query user
💻 33. Check Open TCP Ports and Associated Processes
🐂 GNU
sudo netstat -tulpn
✴️ PowerShell
Get-NetTCPConnection | Select-Object LocalAddress,LocalPort,OwningProcess
💻 34. Search for Files by Name
🐂 GNU
find /path -name "file.txt"
✴️ PowerShell
Get-ChildItem -Path C:\path -Recurse -Filter "file.txt"
💻 35. Schedule a Task (cron / Task Scheduler)
🐂 GNU
crontab -e
✴️ PowerShell
# Simple example to create a scheduled task via PowerShell
$action = New-ScheduledTaskAction -Execute "notepad.exe"
$trigger = New-ScheduledTaskTrigger -At 9am -Daily
Register-ScheduledTask -TaskName "OpenNotepad" -Action $action -Trigger $trigger
💻 36. Clear Screen
🐂 GNU
clear
✴️ PowerShell
Clear-Host
💻 37. Show System Variables (with name and value)
🐂 GNU
env
✴️ PowerShell
Get-ChildItem Env:
💻 38. Compare Files Line by Line
🐂 GNU
diff file1 file2
✴️ PowerShell
Compare-Object (Get-Content file1) (Get-Content file2)
💻 39. Run Local Script (bash / PowerShell)
🐂 GNU
./script.sh
✴️ PowerShell
.\script.ps1
💻 40. Stop Command Execution (Ctrl + C)
🐂 GNU
Ctrl + C
✴️ PowerShell
Ctrl + C
💻 41. Get Command History for Current Session
🐂 GNU
history
✴️ PowerShell
Get-History
💻 42. Get File with Command History
🐂 GNU
cat ~/.bash_history
✴️ PowerShell
Get-Content (Get-PSReadlineOption).HistorySavePath
💻 43. Search Text in Command History
🐂 GNU
history | grep term
✴️ PowerShell
Get-History | Where-Object CommandLine -Match "term"
💻 44. Display Variables Defined in Current Session
🐂 GNU
set
✴️ PowerShell
Get-Variable
💻 45. Define Local Variable (shell/session)
🐂 GNU
VARIABLE=value
✴️ PowerShell
$VARIABLE = "value"
💻 46. Limit Command Output (pager)
🐂 GNU
command | less
✴️ PowerShell
command | Out-Host -Paging
💻 47. Define Alias (command shortcut)
🐂 GNU
alias ll='ls -la'
✴️ PowerShell
Set-Alias ll Get-ChildItem
💻 48. Remove Alias
🐂 GNU
unalias ll
✴️ PowerShell
Remove-Item Alias:ll
💻 49. Show CPU Information
🐂 GNU
lscpu
✴️ PowerShell
Get-CimInstance Win32_Processor | Select-Object Name,NumberOfCores,NumberOfLogicalProcessors
💻 50. Open Text Editor in Terminal
🐂 GNU
vim file.txt
✴️ PowerShell
notepad file.txt
🍖 Bonus:
Download a File:
- GNU:
wget https://url.com/file.zip
# Or: wget https://url.com/file.zip -O newname.zip
- PowerShell:
Invoke-WebRequest -Uri "https://url.com/file.zip" -OutFile "file.zip"
Top comments (0)