Aliases in PowerShell
For a list of aliases in PowerShell, e.g., alias cd for Set-Location, see my previous blog post PowerShell aliases and missing Microsoft documentation (aliases in PowerShell are not in the official Microsoft documentation).
See also my blog post Breaking into PowerShell (2014).
PowerShell also works on Linux!
For instance, on Ubuntu 20.04, it can be installed with (from the command-line):
snap --classic install powershell
The option “–classic” will suppress the scary warning “error: This revision of snap “powershell” was published using classic confinement and thus may perform arbitrary system changes outside of the security sandbox that snaps are usually confined to, which may put your system at risk. If you understand and want to proceed repeat the command including –classic.”
Output:
powershell 7.3.7 from Microsoft PowerShell✓ installed
Launch PowerShell:
pwsh
Output:
PowerShell 7.3.7 PS /home/mortensen>
Running the following line from the first mentioned blog post gave the expected result:
Get-Alias | select Name, Definition, DisplayName | Sort-Object Definition, Name
Though the formatting line fails:
Get-Alias | select Name, Definition, DisplayName | sort Definition, Name | foreach { "<tr> <td>{0,1}</td> <td>{1,1}</td> </tr>" -f $_.Name, $_.Definition }
Output:
/usr/bin/sort: cannot read: Definition,: No such file or directory
Resolution:
Use the cmdlet Sort-Object instead of its alias ‘sort’ (that works on Windows):
Get-Alias | select Name, Definition, DisplayName | Sort-Object Definition, Name | foreach { "<tr> <td>{0,1}</td> <td>{1,1}</td> </tr>" -f $_.Name, $_.Definition }
Portability
As the previous section demonstrated, PowerShell scripts may break when moved from Windows to Linux, at least with the default configuration of PowerShell.
For example, cp, sort, cd, ps, mv, and rm don’t work on Linux. See the next section for some details.
Aliases in PowerShell on Linux (7.3.7)
Note that, unlike on Windows, the aliases corresponding to the native ones on Linux are absent. For example, cp (Copy-Item), sort (Sort-Object), cd (Set-Location), ps (Get-Process), mv (Move-Item), and rm (Remove-Item).
Alias | Cmdlet |
---|---|
clc | Clear-Content |
clhy | Clear-History |
cls | Clear-Host |
cli | Clear-Item |
clp | Clear-ItemProperty |
clv | Clear-Variable |
cvpa | Convert-Path |
copy | Copy-Item |
cpi | Copy-Item |
dbp | Disable-PSBreakpoint |
ebp | Enable-PSBreakpoint |
etsn | Enter-PSSession |
exsn | Exit-PSSession |
epal | Export-Alias |
epcsv | Export-Csv |
% | ForEach-Object |
foreach | ForEach-Object |
fc | Format-Custom |
fhx | Format-Hex |
fl | Format-List |
ft | Format-Table |
fw | Format-Wide |
gal | Get-Alias |
dir | Get-ChildItem |
gci | Get-ChildItem |
gcm | Get-Command |
gc | Get-Content |
type | Get-Content |
gerr | Get-Error |
ghy | Get-History |
h | Get-History |
history | Get-History |
gi | Get-Item |
gp | Get-ItemProperty |
gpv | Get-ItemPropertyValue |
gjb | Get-Job |
gl | Get-Location |
pwd | Get-Location |
gm | Get-Member |
gmo | Get-Module |
gps | Get-Process |
gbp | Get-PSBreakpoint |
gcs | Get-PSCallStack |
gdr | Get-PSDrive |
gsn | Get-PSSession |
gu | Get-Unique |
gv | Get-Variable |
group | Group-Object |
ipal | Import-Alias |
ipcsv | Import-Csv |
ipmo | Import-Module |
icm | Invoke-Command |
iex | Invoke-Expression |
ihy | Invoke-History |
r | Invoke-History |
ii | Invoke-Item |
irm | Invoke-RestMethod |
iwr | Invoke-WebRequest |
measure | Measure-Object |
md | mkdir |
mi | Move-Item |
move | Move-Item |
mp | Move-ItemProperty |
nal | New-Alias |
ni | New-Item |
nmo | New-Module |
ndr | New-PSDrive |
nsn | New-PSSession |
nv | New-Variable |
oh | Out-Host |
popd | Pop-Location |
pushd | Push-Location |
rcjb | Receive-Job |
rcsn | Receive-PSSession |
del | Remove-Item |
erase | Remove-Item |
rd | Remove-Item |
ri | Remove-Item |
rp | Remove-ItemProperty |
rjb | Remove-Job |
rmo | Remove-Module |
rbp | Remove-PSBreakpoint |
rdr | Remove-PSDrive |
rsn | Remove-PSSession |
rv | Remove-Variable |
ren | Rename-Item |
rni | Rename-Item |
rnp | Rename-ItemProperty |
rvpa | Resolve-Path |
select | Select-Object |
sls | Select-String |
sal | Set-Alias |
si | Set-Item |
sp | Set-ItemProperty |
cd | Set-Location |
chdir | Set-Location |
sl | Set-Location |
sbp | Set-PSBreakpoint |
set | Set-Variable |
sv | Set-Variable |
sajb | Start-Job |
saps | Start-Process |
spjb | Stop-Job |
spps | Stop-Process |
wjb | Wait-Job |
? | Where-Object |
where | Where-Object |
echo | Write-Output |
Leave a Reply