Skip to content

Instantly share code, notes, and snippets.

@JimWolff
Last active April 26, 2023 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JimWolff/0db210586fa35e468906c1e71cf7c108 to your computer and use it in GitHub Desktop.
Save JimWolff/0db210586fa35e468906c1e71cf7c108 to your computer and use it in GitHub Desktop.
Powershell to bash equivalent Cheatsheet
PowerShell Command PowerShell Shorthand Bash Equivalent
Get-ChildItem -Path "/path/to/directory" -File -Force -Recurse gci -Path "/path/to/directory" -File -Force -Recurse ls -Rap /path/to/directory | grep -v /$
Select-String -Pattern "search-pattern" -Path "/path/to/files/*" sls "search-pattern" "/path/to/files/*" grep "search-pattern" /path/to/files/*
ForEach-Object { $_.Property } % { $_.Property } `
Get-Content -Path "/path/to/file" gc "/path/to/file" cat /path/to/file
Set-Content -Path "/path/to/file" -Value "content" sc "/path/to/file" "content" echo "content" > /path/to/file
New-Item -ItemType "file" -Path "/path/to/file" ni -ItemType "file" -Path "/path/to/file" touch /path/to/file
New-Item -ItemType "directory" -Path "/path/to/directory" ni -ItemType "directory" -Path "/path/to/directory" mkdir /path/to/directory
Remove-Item -Path "/path/to/file" rm "/path/to/file" rm /path/to/file
Rename-Item -Path "/path/to/file" -NewName "new-name" ren "/path/to/file" "new-name" mv /path/to/file /path/to/new-name
Copy-Item -Path "/path/to/source" -Destination "/path/to/destination" -Recurse cp -r "/path/to/source" "/path/to/destination" cp -r /path/to/source /path/to/destination
Start-Process -FilePath "command.exe" -ArgumentList "-option value" start "command.exe" "-option value" command.exe -option value &
Test-Path -Path "/path/to/file" test-path "/path/to/file" [ -f /path/to/file ] && echo "File exists" || echo "File does not exist"
Out-File -FilePath "/path/to/file" -InputObject "content" echo "content" > "/path/to/file" echo "content" > /path/to/file
Write-Output "output" echo "output" echo "output"
Get-Service -Name "service-name" gsv -Name "service-name" systemctl status service-name
Stop-Service -Name "service-name" stop-service -Name "service-name" systemctl stop service-name
Start-Service -Name "service-name" start-service -Name "service-name" systemctl start service-name
Restart-Service -Name "service-name" restart-service -Name "service-name" systemctl restart service-name
New-NetFirewallRule -DisplayName "Rule Name" -Direction Inbound -LocalPort 8080 -Protocol TCP -Action Allow New-NetFirewallRule -DisplayName "Rule Name" -Direction Inbound -LocalPort 8080 -Protocol TCP -Action Allow sudo ufw allow 8080/tcp
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned Set-ExecutionPolicy RemoteSigned chmod +x /path/to/script
New-Item -ItemType "file" -Path "/path/to/file" -Force ni -ItemType "file" -Path "/path/to/file" -Force touch /path/to/file
Get-Process | Where-Object { $_.ProcessName -eq "process-name" } gps | where-object { \$_.ProcessName -eq "process-name" } ps aux | grep "process-name"
Sort-Object -Property "property" sort -Property "property" sort -k "property"
Measure-Object -Property "property" measure -Property "property" wc -l
Compare-Object -ReferenceObject $array1 -DifferenceObject $array2 compare-object $array1 $array2 diff <(echo $array1) <(echo $array2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment