The other day I was looking something up for PowerShell and realized that cat
command for the classic ‘Windows Command Shell’1 is an alias of Get-Content
PowerShell cmdlet. I wondered what other aliases does PowerShell have. There is an extensive collection of about 138 default aliases on PowerShell going to 109 PowerShell cmdlets on Windows. PowerShell was designed to work with other operating systems too, like Linux and MacOs. If you are new to PowerShell, then these aliases are a good place to learn commands that are often used.
What is an alias?
In PowerShell, an alias is an alternative name for a cmdlet or command element (e.g., function, script, file, executable).
Alias Good Practices
As good practice, I like to write out the entire cmdlet rather than the alias. There are good reasons not to use the aliases in scripts too:
- Easier to read and understand the command, e.g.,
Export-Csv
vsepcsv
. - Aliases can be deleted/redefined in the profile script (more on this)
- Custom aliases may not be available where the script is running (e.g., another system, another OS)
Useful Aliases
List your Aliases
To list your aliases on your system, use Get-Alias
or simply the alias gal
.
Output:
CommandType Name Version Source
----------- ---- ------- ------
Alias ? -> Where-Object
Alias % -> ForEach-Object
Alias ac -> Add-Content
Alias cat -> Get-Content
Alias cd -> Set-Location
Alias chdir -> Set-Location
Additionally can list all alias type but these include ones that don’t have an alias defined:
Get-Command -CommandType Alias
Output:
CommandType Name Version Source
----------- ---- ------- ------
Alias % -> ForEach-Object
Alias ? -> Where-Object
Alias ac -> Add-Content
Alias Add-AppPackage 2.0.1.0 Appx
Alias Add-AppPackageVolume 2.0.1.0 Appx
...
Alias to Cmdlet
If you see an alias you can get its cmdlet by calling the following:
Get-Alias -Name ls
Output:
CommandType Name
----------- ----
Alias ls -> Get-ChildItem
Cmdlet to Aliases
If you want to get all the aliases for a cmdlet:
Get-Alias -Definition Get-ChildItem
CommandType Name
----------- ----
Alias dir -> Get-ChildItem
Alias gci -> Get-ChildItem
Alias ls -> Get-ChildItem
Other Operating Systems
I also noticed that a lot of these aliases are also Linux friendly naming (e.g., clear
, ls
, pwd
). There is a good chance that the command you find for Linux could work for Windows. Good news for developers jumping between operating systems – less to learn. Which makes sense, as PowerShell tries to be cross-platform compatible. As the different shells coalesce into a singular naming convention. #singularity 😄
PowerShell cmdlet | Windows Command Shell1 | UNIX command |
---|---|---|
Clear-Host | cls | clear |
Copy-Item | copy | cp |
Remove-Item | del, erase, rd, rmdir | rm |
Get-ChildItem | dir | ls |
Write-Output | echo | echo |
New-Item | md | mkdir |
Move-Item | move | mv |
Pop-Location | popd | popd |
Get-Location | - | pwd |
Push-Location | pushd | pushd |
Rename-Item | ren | mv |
Get-Content | type | cat |
Default PowerShell Aliases on Windows
I think the default PowerShell aliases on Windows are important because it shows which cmdlets are common enough across different shells to have an alias (e.g., ls
on Linux/MacOS) in Windows, or, used enough that typing out the whole cmdlet is tedious (e.g., Get-History
and h
).
PowerShell Cmdlet | PowerShell Alias on Windows |
---|---|
Clear-Content | clc |
Clear-History | clhy |
Clear-Host | clear , cls |
Clear-Item | cli |
Clear-ItemProperty | clp |
Clear-Variable | clv |
Compare-Object | compare , diff |
Connect-PSSession | cnsn |
Convert-Path | cvpa |
Copy-Item | copy , cp , cpi |
Copy-ItemProperty | cpp |
Disable-PSBreakpoint | dbp |
Disconnect-PSSession | dnsn |
Enable-PSBreakpoint | ebp |
Enter-PSSession | etsn |
Exit-PSSession | exsn |
Export-Alias | epal |
Export-Csv | epcsv |
ForEach-Object | foreach , % |
Format-Custom | fc |
Format-Hex | fhx |
Format-List | fl |
Format-Table | ft |
Format-Wide | fw |
Get-Alias | gal |
Get-ChildItem | dir , gci , ls |
Get-Clipboard | gcb |
Get-Command | gcm |
Get-ComputerInfo | gin |
Get-Content | cat , gc , type |
Get-Error | gerr |
Get-History | ghy , h , history |
Get-Item | gi |
Get-ItemProperty | gp |
Get-ItemPropertyValue | gpv |
Get-Job | gjb |
Get-Location | gl , pwd |
Get-Member | gm |
Get-Module | gmo |
Get-Process | gps , ps |
Get-PSBreakpoint | gbp |
Get-PSCallStack | gcs |
Get-PSDrive | gdr |
Get-PSSession | gsn |
Get-Service | gsv |
Get-TimeZone | gtz |
Get-Unique | gu |
Get-Variable | gv |
Group-Object | group |
help | man |
Import-Alias | ipal |
Import-Csv | ipcsv |
Import-Module | ipmo |
Invoke-Command | icm |
Invoke-Expression | iex |
Invoke-History | ihy , r |
Invoke-Item | ii |
Invoke-RestMethod | irm |
Invoke-WebRequest | iwr |
Measure-Object | measure |
mkdir | md |
Move-Item | mi , move , mv |
Move-ItemProperty | mp |
New-Alias | nal |
New-Item | ni |
New-Module | nmo |
New-PSDrive | mount , ndr |
New-PSSession | nsn |
New-Variable | nv |
Out-GridView | ogv |
Out-Host | oh |
Pop-Location | popd |
Push-Location | pushd |
Receive-Job | rcjb |
Receive-PSSession | rcsn |
Remove-Item | del , erase , rd , ri , rm , rmdir |
Remove-ItemProperty | rp |
Remove-Job | rjb |
Remove-Module | rmo |
Remove-PSBreakpoint | rbp |
Remove-PSDrive | rdr |
Remove-PSSession | rsn |
Remove-Variable | rv |
Rename-Item | ren , rni |
Rename-ItemProperty | rnp |
Resolve-Path | rvpa |
Select-Object | select |
Select-String | sls |
Set-Alias | sal |
Set-Clipboard | scb |
Set-Item | si |
Set-ItemProperty | sp |
Set-Location | cd , chdir , sl |
Set-PSBreakpoint | sbp |
Set-TimeZone | stz |
Set-Variable | set , sv |
Show-Command | shcm |
Sort-Object | sort |
Start-Job | sajb |
Start-Process | saps , start |
Start-Service | sasv |
Start-Sleep | sleep |
Stop-Job | spjb |
Stop-Process | kill , spps |
Stop-Service | spsv |
Tee-Object | tee |
Wait-Job | wjb |
Where-Object | where |
Write-Output | echo , write |