Short Names: Aliases

An alias is a short second name for a command, such as ls or dir for Get-ChildItem, and Get-Alias shows what an alias really runs, so you can use short names at the prompt and full names in scripts.

Novice · PowerShell · Updated

After this lesson you can

  • Find what an alias really runs, or a command's aliases, with Get-Alias
  • Choose short names at the prompt and full names in scripts, and explain why

Key takeaways

  • An alias is a second, shorter name for a command. ls, dir and gci all run Get-ChildItem.
  • Get-Alias ls shows what an alias runs, and Get-Alias -Definition Get-ChildItem shows a command's aliases.
  • An alias changes only the name. The parameters are still the full command's, so ls -la doesn't work in PowerShell.
  • Use short names at the prompt to save typing, and full names in scripts, so anyone can read them on any computer.

You're following three tutorials. The first says to type ls, the second dir, and the third gci. One was written by someone who learned on a Mac, one by someone who grew up with the old Windows Command Prompt, and one by someone who uses PowerShell every day. All three run the same command, Get-ChildItem, the one that lists what's inside a folder. Reading other people's commands means knowing their short names, and this lesson shows you how to look them up.

Nicknames for commands

Elizabeth's friends call her Liz. It's the same person, and a shorter name. PowerShell has nicknames too, called aliases: a second, shorter name for a command. Get-Alias shows what an alias stands for:

Get-Alias ls
CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           ls -> Get-ChildItem

The arrow -> is read "points to": ls points to Get-ChildItem. You can ask about several at once, with commas between them:

Get-Alias dir, cd, cat, cls, pwd, gsv, gps
CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           dir -> Get-ChildItem
Alias           cd -> Set-Location
Alias           cat -> Get-Content
Alias           cls -> Clear-Host
Alias           pwd -> Get-Location
Alias           gsv -> Get-Service
Alias           gps -> Get-Process

On Windows, PowerShell 7.6 starts with 135 aliases. Many are the names people already knew from other shells (dir and cls from Command Prompt; ls, cat and pwd from the Mac and Linux). Others are made from the verb's and noun's first letters: gsv is get-service.

A command's short names

The question also goes the other way: "does this command have a short name?" -Definition asks it:

Get-Alias -Definition Get-Process
CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           gps -> Get-Process
Alias           ps -> Get-Process

Not every command has one. Get-Alias -Definition Get-Date says that no alias with that definition exists.

An alias changes only the name

On a Mac or in Linux, ls -la lists everything in a folder, hidden files included. Try it in PowerShell on Windows:

ls -la
Get-ChildItem: A parameter cannot be found that matches parameter name 'la'.

The error starts with Get-ChildItem, not ls, because that's what really ran. An alias gives a command a new name, but the parameters are still the full command's own. Get-ChildItem's parameter for hidden files is -Force, so the PowerShell way is ls -Force.

Short names at the prompt, full names in scripts

Both kinds of name are right; each fits a different place.

  • At the prompt, use whichever you like. You're the only reader, and fewer keystrokes is faster.
  • In a script, a file of commands that you save and run again (Module 6 is all about them), write the full names. A script is read by other people, or by you in six months, and Get-ChildItem says what it does where gci doesn't. Tab types the long name for you anyway.

There's a second reason. On a Mac or Linux, ls, cat, ps and a few others aren't aliases in PowerShell: they run the system's own programs, which take different parameters and print text instead of PowerShell's tables. A script that says Get-ChildItem works the same everywhere. Aliases can also differ between versions: Windows PowerShell 5.1 has curl and wget as aliases for Invoke-WebRequest, and PowerShell 7 dropped them so the real curl program runs.

That's why this course writes full names in its code. You can make aliases of your own, too: Aliases and Small Functions, in Module 5, shows how.

Try it. Run Get-Alias -Definition Get-Content. Which of its short names have you seen in a tutorial?

Check yourself

2 questions to try on the lesson page.

So what

Short names make you quick at the prompt, and Get-Alias turns any short name you meet back into a full name that explains itself.

Key terms

Cheat sheets

Related