50 GNU Commands X 50 PowerShell Commands

πŸ‚ πŸ†š ✴️ Everyday terminal commands used in GNU and their PowerShell equivalents.


50 GNU Commands X 50 PowerShell Commands


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"  

πŸ‘“ See Also:

πŸ”— 7 PowerShell Usage Examples

πŸ”— Discover 7 GNU Tools That Power the Command Line

πŸ”— 10 Tips for GNU GCC Flags and Parameters

πŸ”— Customize Your PowerShell Like a Pro


powershell gnu commands


Share


YouTube channel

Subscribe


Marcos Oliveira

Marcos Oliveira

Software developer
https://github.com/terroo

Related articles