r/PowerShell • u/fa_foon • Oct 18 '26
Question alias ls works but alias doesn't exist anywhere — what is it?
Title:
On PowerShell 5.1 (Windows 11 24H2, build 26100.9711), running alias ls gives valid output:
PS C:\> alias ls
CommandType Name Version Source
----------- ---- ------- ------
Alias ls -> Get-ChildItemBut every way I know to look it up says it doesn't exist:
Get-Alias alias # ItemNotFoundException
Get-Command alias # CommandNotFoundException
Get-Command -Name 'alias' -CommandType Alias, Function, Cmdlet -ErrorAction SilentlyContinue # returns nothing
Get-Item Alias:\alias -ErrorAction SilentlyContinue # returns nothingNo $PROFILE exists. Only standard modules are loaded. What is alias actually doing here?
8
Upvotes
21
u/surfingoldelephant Oct 18 '26 edited Oct 18 '26
Command discovery tries with
Get-if it can't find a command. You can see it withTrace-Command:Which outputs:
It does this for any non-existent command that doesn't have
Verb-, but it's expensive as it has to look inPATHfirst.Get-Commandis missing the logic. See issue #3987.9
u/joshooaj Oct 18 '26
I think what you're experiencing is the way that PowerShell will assume the verb is "get" if you leave out the verb.
So "alias" is the same as "get-alias" because the "get" is assumed. Try "computerinfo" for example.
4
u/BlackV Oct 18 '26 edited Oct 19 '26
For your example you wantGet-Alias lsGet-Command lsGet-Command -Name 'ls' -CommandType Alias, Function, Cmdlet -ErrorAction SilentlyContinueGet-Item Alias:\lsAliasit's self is term, like an internal function to PowerShell rather than a direct commandEdit: Oh I see what you mean
Get-apologies misunderstood, its been well answered now1
u/Mr-Fly72 Oct 25 '26
And the best example to not trust aliases is the alias command itself ;-)
On Mac/Linux, alias is not defined as an alias, as there is a shell command alias (/usr/bin/alias)
1
u/narcissisadmin Oct 20 '26
I looked up the word thesaurus in the dictionary and it said "you're being an ass". 🤣
I was amused by this behavior and eventually figure out why it was happening, /u/surfingoldelephant explained it well.
0
u/hemping0 Oct 18 '26
tbh i think what you're seeing is that
aliasis a default alias forGet-Aliasloaded at startup, so runningalias lsis really justGet-Alias ls. the reason you cant findaliasitself is a bit circular, tryGet-Alias | Where-Object Name -eq 'alias'and see if it shows up there.-3
u/jimb2 Oct 19 '26
The command ls comes from unix. It was listf for "list files" in earlier operating systems then only the common standard abbreviation ls was transferred to the early unix systems. It remains standard in unix/linux/etc.
PowerShell was designed to work like the various unix command line and scripting shells so incorporated unix commands as aliases where possible. Unix people could migrate with their muscle-memory basic command names intact. The radical and powerful innovation of PowerShell was that the results of functions are well-defined objects, not flat lines of text. That was a beautiful thing!
Powershell also supports the older DOS/Command promt commands as aliases, eg
These can be used interchangeably.