- 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. Heredir
producesFileInfo
objects and thussls
searches in the content of the files represented byFileInfo
objects, rather than theToString()
result ofFileInfo
objects. If the input is plain text, thensls
just searches in the text and there is no magic like theFileInfo
inputs.
Bash
find 'dir' -type f -name '*.txt' ! \( -exec grep -q 'pattern' '{}' \; \) -print
PowerShell
dir 'dir\*.txt' -Recurse | ?{ !(sls -Quiet -Path $_ -Pattern 'pattern') }
Bash
find 'dir' -name '*.txt' -delete
PowerShell
dir 'dir\*.txt' -Recurse | rm
Bash
head 'file'
tail 'file'
PowerShell
cat 'file' -Head 10
cat 'file' -Tail 10
Bash
... | head
... | tail
PowerShell
... | select -First 10
... | select -Last 10
Bash
type -a 'command'
PowerShell
Get-Command -all 'command'
Bash
<command write to stdout> | grep 'pattern'
PowerShell
<command write to stdout> | oss | sls 'pattern'