- Bash commands output strings while PS commands output objects!
The following standard aliases in PowerShell are used:
- dir -> Get-ChildItem
- sls -> Select-String
- cat -> Get-Content
- rm -> Remove-Item
- cp -> Copy-Item
- select -> Select-Object
- ? -> Where-Object
- % -> ForEach-Object
Bash
find 'dir' -type f -name '*.txt' -exec grep -n 'pattern' '{}' +PowerShell
dir 'dir\*.txt' -Recurse | sls 'pattern'NOTE
sls' behavior in pipeline depends on the type of input objects. HeredirproducesFileInfoobjects and thusslssearches in the content of the files represented byFileInfoobjects, rather than theToString()result ofFileInfoobjects. If the input is plain text, thenslsjust searches in the text and there is no magic like theFileInfoinputs.
Bash
find 'dir' -type f -name '*.txt' ! \( -exec grep -q 'pattern' '{}' \; \) -printPowerShell
dir 'dir\*.txt' -Recurse | ?{ !(sls -Quiet -Path $_ -Pattern 'pattern') }Bash
find 'dir' -name '*.txt' -deletePowerShell
dir 'dir\*.txt' -Recurse | rmBash
head 'file'
tail 'file'PowerShell
cat 'file' -Head 10
cat 'file' -Tail 10Bash
... | head
... | tailPowerShell
... | select -First 10
... | select -Last 10Bash
type -a 'command'PowerShell
Get-Command -all 'command'Bash
<command write to stdout> | grep 'pattern'PowerShell
<command write to stdout> | oss | sls 'pattern'