PowerShell aliases (alias)

Source: Internet
Author: User
Tags aliases

In the previous section, we described how to retrieve all the available commands in the current shell and PowerShell, and for the specified command to view their syntax information, you can get help information for the specified command, including getting the online Help topic, detailed content timestamp here.


In this section, you mainly describe the alias for PowerShell, which mainly includes the following.

    1. Familiarize yourself with the common aliases.

    2. Specification of standard aliases and creation of new aliases.

    3. The compatibility alias in PowerShell.

    4. Summarize


familiar with common aliases

An alias, a popular point, is another name, and the alias associates the command entered with another command. For example, "Mimi" is the nickname for "Cat". By using aliases, PowerShell allows users to reference commands using alternate commands. Furthermore, aliases enable users with other shell experience to reuse these commands in PowerShell to perform similar operations.

For example, PowerShell has an intrinsic function called clear-host , which is used to clear the Output window. If you enter the CLS or the clear command at the command prompt, PowerShell interprets this command as an alias for the Clear-host function and allows the Clear-host function.

The alias feature of PowerShell is very helpful for developers to learn about PowerShell, and most cmd.exe or UNIX users have a large list of commands that they remember by name. Their formal similarity is enough to allow developers to use these commands directly to complete their work without first remembering the PowerShell command name.

The following is a short list of common Cmd.exe and UNIX commands that you can use in PowerShell.

Cat
Dir
Mount
Rm
Cd
Echo
Move
RmDir
ChDir
Erase
popd
Sleep
Clear
H
Ps
Sort
Cls
History
pushd
Tee
Copy
Kill Pwd
Type
Del
Lp
R
Write
Diff
Ls
ren

If you frequently use one of these commands and want to know its true name in PowerShell, you can pass the Get-alias command.

ps c:\documents and settings\administrator> get-alias clscommandtype      Name                                                   Definition-----------     ----                                                   ----------alias           cls                                                    clear-host

As for aliases, it is important to note that if you are working with PowerShell scripts or code snippets from other sources, or if you want to define your own aliases, the early information about the alias is significant. You should also be aware that each developer can define his or her own alias, so in team collaboration scripting, you should try to avoid using aliases.


Specification for standard aliases

The aliases mentioned above are designed to achieve compatibility with other shell command names, but PowerShell's built-in aliases are often designed for brevity and simplicity, and these short commands are easy to enter, but they cannot be interpreted correctly without understanding their meaning.

PowerShell balances clarity and brevity by providing a set of standard aliases based on shorthand names for commonly used verbs and nouns. In the core aliases of a common set of cmdlets, you can interpret these commands by simply knowing the shorthand names. For example, in the standard alias, the verb Get abbreviation is g, the verb Set abbreviation is s, the noun Item abbreviation is i, the noun location abbreviation is l, and the noun Command abbreviation is cm. Please refer to the examples in the table below.

PS (Powershell) command PS (Powershell) aliases
Get-Item
Gi
Set-Item
Si
Get-Location
Gl
Set-Location
Sl
Get-Command
Gcm


Create a new Alias

The PowerShell command Set-alias cmdlet can create aliases, such as the following aliases can be created.

Set-alias-name gi-value get-itemset-alias-name si-value set-itemset-alias-name gl-value get-locationset-alias-name Sl-value set-locationset-alias-name Gcm-value Get-command

Internally, this type of command is used when PowerShell is started. It is important to note that the PowerShell built-in aliases (5 aliases above are built-in aliases) are read-only or commonplace, meaning that the PowerShell built-in aliases are not modifiable .


Compatibility aliases in PowerShell

PowerShell has several conversion aliases that allow UNIX and CMD developers to use familiar command names in PowerShell. The following table lists the most commonly used aliases and the PowerShell commands behind the aliases and the standard PowerShell aliases (if any). As mentioned earlier, you can use the Get-alias cmdlet to find the PowerShell command corresponding to the alias, such as the Get-alias CLS .


CMD command
UNIX Commands PS (Powershell) command PS (Powershell) aliases
Dir Ls Get-childitem
Gci
Cls
Clear
Clear-host (function)
Not available
Del,erase,rmdir
Rm
Remove-item
Ri
Copy
Cp Copy-item
Ci
Move
Mv Move-item
Mi
Rename Mv
Rename-item
Rni
Type
Cat
Get-content
Gc
Cd
Cd Set-location
Sl
Md
Mkdir
New-item
Ni
Not available pushd
Push-location
Not available
Not available popd
Pop-location
Not available


Summarize

By learning this section, you should be familiar with the following content

    1. The aliases that are common in PowerShell and the actual PowerShell commands are viewed through aliases.

    2. The alias naming specification for PowerShell and creating a new alias (the PowerShell built-in alias cannot be changed).

    3. Know the compatibility aliases in PowerShell

This article from "Flower Blossom Fall" blog, declined reprint!

PowerShell aliases (alias)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.