PowerShell ↔ Unix Command Reference

Complete guide with proper examples and explanations

200+ commands • 15 categories • 600+ examples

---

🔧 Text Processing and Filtering

Where-Object → grep / awk

Aliases: where, ?

Description: Filter objects based on conditions

Examples:


# Filter by property value
Get-Process | Where-Object {$_.Name -eq "notepad"}

# Filter by multiple conditions
Get-Process | Where-Object {$_.CPU -gt 100 -and $_.Name -like "chrome*"}

# Filter files by size
Get-ChildItem | Where-Object {$_.Length -gt 1MB}

# Using comparison operators
Get-Service | Where-Object {$_.Status -ne "Running"}

# Using alias (? symbol)
Get-Process | ? {$_.Name -like "*chrome*"}

# Simplified syntax (PowerShell 3.0+)
Get-Process | Where-Object Name -eq "notepad"

---

ForEach-Object → xargs

Aliases: foreach, %

Description: Process each object in the pipeline

Examples:


# Process each item
1..5 | ForEach-Object {Write-Host "Number: $_"}

# Transform objects
Get-ChildItem | ForEach-Object {$_.Name.ToUpper()}

# Perform action on each file
Get-ChildItem "*.txt" | ForEach-Object {Copy-Item $_ "backup\"}

# Using alias (% symbol)
Get-Process | % {$_.Name}

# Complex processing
Get-Service | ForEach-Object {
    if ($_.Status -eq "Running") {
        "$($_.Name) is running"
    }
}

---

Select-Object → cut / awk

Aliases: select

Description: Select specific properties from objects

Examples:


# Select specific properties
Get-Process | Select-Object Name, CPU, WorkingSet

# Select first N objects
Get-Process | Select-Object -First 5

# Select last N objects
Get-ChildItem | Select-Object -Last 3

# Skip and take
Get-Process | Select-Object -Skip 10 -First 5

# Select unique values
Get-Process | Select-Object ProcessName -Unique

# Create calculated properties
Get-Process | Select-Object Name, @{Name="CPU%";Expression={$_.CPU / 100}}

---

Sort-Object → sort

Aliases: sort

Description: Sort objects by property values

Examples:


# Sort by single property
Get-Process | Sort-Object Name

# Sort descending
Get-ChildItem | Sort-Object Length -Descending

# Sort by multiple properties
Get-Process | Sort-Object CPU, Name

# Sort text lines
Get-Content "file.txt" | Sort-Object

# Sort with custom expression
Get-ChildItem | Sort-Object @{Expression={$_.Length}; Descending=$true}

---

Group-Object → uniq -c

Aliases: group

Description: Group objects by property values

Examples:


# Group by property
Get-Process | Group-Object ProcessName

# Group and sort by count
Get-Process | Group-Object ProcessName | Sort-Object Count -Descending

# Group files by extension
Get-ChildItem | Group-Object Extension

# Group with no element collection
Get-Service | Group-Object Status -NoElement

---

Measure-Object → wc

Aliases: measure

Description: Calculate statistics for objects

Examples:


# Count objects
Get-Process | Measure-Object

# Count lines in file
Get-Content "file.txt" | Measure-Object -Line

# Count words and characters
Get-Content "file.txt" | Measure-Object -Word -Character

# Calculate sum and average
Get-Process | Measure-Object CPU -Sum -Average -Maximum

# Measure file sizes
Get-ChildItem | Measure-Object Length -Sum -Average

---

Compare-Object → diff

Aliases: compare, diff

Description: Compare two sets of objects

Examples:


# Compare two files
Compare-Object (Get-Content "file1.txt") (Get-Content "file2.txt")

# Compare arrays
Compare-Object @(1,2,3) @(2,3,4)

# Show only differences
Compare-Object $list1 $list2 -ExcludeDifferent

# Include equal items
Compare-Object $list1 $list2 -IncludeEqual

---

Tee-Object → tee

Aliases: tee

Description: Send output to file and continue in pipeline

Examples:


# Save to file and continue
Get-Process | Tee-Object -FilePath "processes.txt" | Where-Object {$_.CPU -gt 50}

# Append to file
Get-Date | Tee-Object -FilePath "log.txt" -Append | Write-Host

# Save to variable
Get-Process | Tee-Object -Variable processlist | Select-Object -First 5

---

⚙️ Process Management

Get-Process → ps

Aliases: gps, ps

Description: List running processes

Examples:


# List all processes
Get-Process

# Get specific process
Get-Process -Name "notepad"

# Get process by ID
Get-Process -Id 1234

# Get processes with wildcard
Get-Process -Name "*chrome*"

# Include process modules
Get-Process -Name "explorer" -Module

# Using alias
ps notepad

---

Stop-Process → kill

Aliases: spps, kill

Description: Terminate processes

Examples:


# Stop process by name
Stop-Process -Name "notepad"

# Stop process by ID
Stop-Process -Id 1234

# Force stop (no graceful shutdown)
Stop-Process -Name "chrome" -Force

# Stop with confirmation
Stop-Process -Name "important-app" -Confirm

# Stop multiple processes
Get-Process "*chrome*" | Stop-Process

# Using alias
kill -Name notepad

---

Start-Process → nohup / &

Aliases: saps, start

Description: Start new process

Examples:


# Start simple application
Start-Process -FilePath "notepad.exe"

# Start with arguments
Start-Process -FilePath "notepad.exe" -ArgumentList "C:\file.txt"

# Start maximized
Start-Process -FilePath "calc.exe" -WindowStyle Maximized

# Start and wait for completion
Start-Process -FilePath "setup.exe" -Wait

# Start with different credentials
Start-Process -FilePath "cmd.exe" -Credential (Get-Credential)

# Return process object
$proc = Start-Process -FilePath "notepad.exe" -PassThru

---

Wait-Process → wait

Description: Wait for process to complete

Examples:


# Wait for process by name
Wait-Process -Name "setup"

# Wait for process by ID
Wait-Process -Id 1234

# Wait with timeout
Wait-Process -Name "setup" -Timeout 300

# Wait for multiple processes
Wait-Process -Name "app1", "app2"

---

🖥️ System Information

Get-ComputerInfo → uname -a / hostinfo

Description: Get detailed computer information

Examples:


# Get all computer info
Get-ComputerInfo

# Get specific properties
Get-ComputerInfo | Select-Object WindowsProductName, TotalPhysicalMemory

# Get OS information
Get-ComputerInfo -Property "*OS*"

# Get hardware info
Get-ComputerInfo -Property "*Processor*", "*Memory*"

---

Get-Service → systemctl / service

Aliases: gsv

Description: List and manage system services

Examples:


# List all services
Get-Service

# Get specific service
Get-Service -Name "Spooler"

# Filter running services
Get-Service | Where-Object {$_.Status -eq "Running"}

# Search services with wildcard
Get-Service -Name "*network*"

# Include dependent services
Get-Service -Name "Spooler" -DependentServices

---

Start-Service → systemctl start

Aliases: sasv

Description: Start system services

Examples:


# Start single service
Start-Service -Name "Spooler"

# Start multiple services
Start-Service -Name "Spooler", "BITS"

# Start service and show result
Start-Service -Name "Spooler" -PassThru

---

Stop-Service → systemctl stop

Aliases: spsv

Description: Stop system services

Examples:


# Stop single service
Stop-Service -Name "Spooler"

# Force stop service
Stop-Service -Name "Spooler" -Force

# Stop with confirmation
Stop-Service -Name "ImportantService" -Confirm

---

Restart-Service → systemctl restart

Description: Restart system services

Examples:


# Restart service
Restart-Service -Name "Spooler"

# Force restart
Restart-Service -Name "Spooler" -Force

# Restart and show result
Restart-Service -Name "Spooler" -PassThru

---

Get-Date → date

Description: Get current date and time

Examples:


# Get current date/time
Get-Date

# Format date
Get-Date -Format "yyyy-MM-dd HH:mm:ss"

# Get specific date component
Get-Date -UFormat "%Y-%m-%d"

# Add/subtract time
Get-Date -Hour 0 -Minute 0 -Second 0

# Convert to UTC
(Get-Date).ToUniversalTime()

---

Get-EventLog → tail /var/log/* / journalctl

Description: Read Windows event logs (classic logs)

Examples:


# Get recent system events
Get-EventLog -LogName System -Newest 10

# Get error events only
Get-EventLog -LogName System -EntryType Error -Newest 5

# Get events from specific source
Get-EventLog -LogName Application -Source "Application Error"

# Get events after specific date
Get-EventLog -LogName System -After (Get-Date).AddDays(-1)

---

Get-WinEvent → journalctl

Description: Read Windows event logs (modern, all logs)

Examples:


# Get recent system events
Get-WinEvent -LogName System -MaxEvents 10

# Filter by event ID
Get-WinEvent -FilterHashtable @{LogName='System'; ID=1074}

# Get events from last 24 hours
Get-WinEvent -FilterHashtable @{LogName='System'; StartTime=(Get-Date).AddDays(-1)}

# Filter by level (Error = 2)
Get-WinEvent -FilterHashtable @{LogName='System'; Level=2}

---

📁 File and Directory Operations

Get-ChildItem → ls

Aliases: gci, ls, dir

Description: List files and directories

Examples:


# Basic listing
Get-ChildItem

# List specific directory
Get-ChildItem -Path "C:\Users"

# Recursive listing
Get-ChildItem -Recurse

# Filter by file type
Get-ChildItem -Filter "*.txt"

# Include hidden files
Get-ChildItem -Force

# Using alias (Unix-style)
ls -la

---

Set-Location → cd

Aliases: sl, cd, chdir

Description: Change current working directory

Examples:


# Change to specific directory
Set-Location -Path "C:\Users"

# Go to parent directory
Set-Location ..

# Go to home directory
Set-Location ~

# Using alias
cd "C:\Program Files"

---

Get-Location → pwd

Aliases: gl, pwd

Description: Get current working directory

Examples:


# Show current directory
Get-Location

# Get just the path string
(Get-Location).Path

# Using alias
pwd

---

New-Item → touch / mkdir

Aliases: ni

Description: Create new files or directories

Examples:


# Create empty file
New-Item -Path "file.txt" -ItemType File

# Create file with content
New-Item -Path "file.txt" -ItemType File -Value "Hello World"

# Create directory
New-Item -Path "MyFolder" -ItemType Directory

# Create nested directories
New-Item -Path "Path\To\Deep\Folder" -ItemType Directory -Force

# Using alias
ni file.txt -ItemType File

---

Remove-Item → rm / rmdir

Aliases: ri, rm, del, erase, rmdir, rd

Description: Delete files or directories

Examples:


# Delete single file
Remove-Item -Path "file.txt"

# Delete multiple files
Remove-Item -Path "*.tmp"

# Delete directory and contents
Remove-Item -Path "MyFolder" -Recurse

# Force delete (no confirmation)
Remove-Item -Path "file.txt" -Force

# Delete with confirmation
Remove-Item -Path "important.txt" -Confirm

# Using alias
rm file.txt

---

Copy-Item → cp

Aliases: ci, cp, copy

Description: Copy files or directories

Examples:


# Copy single file
Copy-Item -Path "source.txt" -Destination "copy.txt"

# Copy to different directory
Copy-Item -Path "file.txt" -Destination "C:\Backup\"

# Copy multiple files
Copy-Item -Path "*.txt" -Destination "C:\Backup\"

# Copy directory (need -Recurse)
Copy-Item -Path "MyFolder" -Destination "C:\Backup\" -Recurse

# Overwrite existing files
Copy-Item -Path "file.txt" -Destination "C:\Backup\" -Force

# Using alias
cp file.txt backup.txt

---

Move-Item → mv

Aliases: mi, mv, move

Description: Move or rename files and directories

Examples:


# Rename file
Move-Item -Path "oldname.txt" -Destination "newname.txt"

# Move file to directory
Move-Item -Path "file.txt" -Destination "C:\NewLocation\"

# Move and rename
Move-Item -Path "file.txt" -Destination "C:\NewLocation\newname.txt"

# Move directory
Move-Item -Path "MyFolder" -Destination "C:\NewLocation\"

# Using alias
mv oldfile.txt newfile.txt

---

Rename-Item → mv

Aliases: rni, ren

Description: Rename files and directories

Examples:


# Rename file
Rename-Item -Path "oldname.txt" -NewName "newname.txt"

# Rename directory
Rename-Item -Path "OldFolder" -NewName "NewFolder"

# Using alias
ren oldfile.txt newfile.txt

---

Test-Path → test -e / [ -e ]

Description: Test if a path exists

Examples:


# Check if file exists
Test-Path -Path "file.txt"

# Check if directory exists
Test-Path -Path "C:\MyFolder" -PathType Container

# Check if file (not directory)
Test-Path -Path "file.txt" -PathType Leaf

# Use in conditional
if (Test-Path "file.txt") { "File exists" }

---

📄 File Content Operations

Get-Content → cat / less / more

Aliases: gc, cat, type

Description: Read and display file contents

Examples:


# Display entire file
Get-Content -Path "file.txt"

# Show last 10 lines (like tail)
Get-Content -Path "logfile.txt" -Tail 10

# Follow file changes (like tail -f)
Get-Content -Path "logfile.txt" -Wait

# Read specific lines
Get-Content -Path "file.txt" -TotalCount 5

# Read as raw string (no line breaks)
Get-Content -Path "file.txt" -Raw

# Using alias
cat file.txt

---

Set-Content → > (redirect)

Aliases: sc

Description: Write content to file (overwrites existing content)

Examples:


# Write text to file
Set-Content -Path "file.txt" -Value "Hello World"

# Write multiple lines
Set-Content -Path "file.txt" -Value @("Line 1", "Line 2", "Line 3")

# Specify encoding
Set-Content -Path "file.txt" -Value "Content" -Encoding UTF8

# Using pipeline
"Hello World" | Set-Content -Path "file.txt"

---

Add-Content → >> (append)

Aliases: ac

Description: Append content to existing file

Examples:


# Append text
Add-Content -Path "file.txt" -Value "New line"

# Append with timestamp
Add-Content -Path "log.txt" -Value "$(Get-Date): Error occurred"

# Append multiple lines
Add-Content -Path "file.txt" -Value @("Line 1", "Line 2")

# Using pipeline
"New content" | Add-Content -Path "file.txt"

---

Out-File → > / tee

Description: Send output to a file

Examples:


# Redirect command output
Get-Process | Out-File -FilePath "processes.txt"

# Append to file
Get-Date | Out-File -FilePath "log.txt" -Append

# Specify encoding
Get-Process | Out-File -FilePath "processes.txt" -Encoding UTF8

# Set width for formatting
Get-Process | Out-File -FilePath "processes.txt" -Width 200

---

Select-String → grep

Aliases: sls

Description: Search for text patterns in files

Examples:


# Search in single file
Select-String -Path "file.txt" -Pattern "error"

# Search in multiple files
Select-String -Path "*.log" -Pattern "error"

# Case-insensitive search
Select-String -Path "file.txt" -Pattern "ERROR" -CaseSensitive

# Show context lines
Select-String -Path "file.txt" -Pattern "error" -Context 2,3

# Regular expression
Select-String -Path "file.txt" -Pattern "\d{3}-\d{3}-\d{4}"

# Using alias
sls "error" file.txt

---

Quick Reference Table

| Category | PowerShell | Unix | Aliases |

|----------|------------|------|---------|

| List files | Get-ChildItem | ls | gci, ls, dir |

| Change directory | Set-Location | cd | sl, cd |

| Current directory | Get-Location | pwd | gl, pwd |

| Copy files | Copy-Item | cp | ci, cp, copy |

| Move files | Move-Item | mv | mi, mv, move |

| Delete files | Remove-Item | rm | ri, rm, del |

| View file | Get-Content | cat | gc, cat, type |

| Search text | Select-String | grep | sls |

| List processes | Get-Process | ps | gps, ps |

| Kill process | Stop-Process | kill | spps, kill |

| Filter objects | Where-Object | grep | where, ? |

| Transform objects | ForEach-Object | xargs | foreach, % |

| Sort data | Sort-Object | sort | sort |

| Count/measure | Measure-Object | wc | measure |

---

Tips for Unix Users

1. Aliases: PowerShell includes many Unix-style aliases (ls, cd, pwd, cat, ps, etc.)

2. Pipes: PowerShell pipes work similarly but pass objects, not just text

3. Tab Completion: Extensive tab completion for commands, parameters, and file paths

4. Get-Help: Use Get-Help for detailed help (equivalent to man)

5. Case Insensitive: PowerShell commands and parameters are case-insensitive

6. Execution Policy: You may need to set execution policy: Set-ExecutionPolicy RemoteSigned

---

Common Patterns

Unix → PowerShell Equivalents


# Unix
find . -name "*.txt" -exec rm {} \;

# PowerShell
Get-ChildItem -Recurse -Filter "*.txt" | Remove-Item

# Unix
ps aux | grep chrome | awk '{print $2}' | xargs kill

# PowerShell
Get-Process *chrome* | Stop-Process

# Unix
tail -f /var/log/syslog

# PowerShell
Get-Content C:\Windows\System32\LogFiles\* -Wait

# Unix
du -sh *

# PowerShell
Get-ChildItem | ForEach-Object {
    if ($_.PSIsContainer) {
        "{0:N2} MB`t{1}" -f ((Get-ChildItem $_ -Recurse | Measure-Object Length -Sum).Sum / 1MB), $_.Name
    } else {
        "{0:N2} MB`t{1}" -f ($_.Length / 1MB), $_.Name
    }
}