Home >php教程 >PHP开发 >Example of using Get-Alias ​​command to obtain cmdlet alias in PowerShell

Example of using Get-Alias ​​command to obtain cmdlet alias in PowerShell

高洛峰
高洛峰Original
2016-12-29 13:22:331697browse

In order to maintain compatibility with the original cmd command in PowerShell, aliases are specially set for many cmdlets. These aliases have the same name as the cmd command, but they represent a cmdlet in PowerShell. For example, the dir cmd command is used to list subfolders and files in a directory. In PowerShell, there is a Get-ChildItem cmdlet, which is also used to list subfolders and files in a directory, so Microsoft Set an alias named dir to Get-ChildItem.

In PowerShell, use the Get-Alias ​​cmdlet to list all aliases and their corresponding cmdlets.

PS C:\Users\zhanghong> Get-Alias
CommandType     Name                            Definition
-----------     ----                            ----------
Alias           %                               ForEach-Object
Alias           ?                               Where-Object
Alias           cat                             Get-Content
Alias           cd                              Set-Location
Alias           chdir                           Set-Location
Alias           clear                           Clear-Host
Alias           clhy                            Clear-History
Alias           cls                             Clear-Host
Alias           clv                             Clear-Variable
Alias           compare                         Compare-Object
Alias           copy                            Copy-Item
Alias           cp                              Copy-Item
Alias           cpi                             Copy-Item
……

The editor has only listed a few of them here. If you are interested, you can check them out one by one.


Have you noticed the following points from the display content given above:

1. The alias can also be a question mark (?), Something like a percent sign (%)
2. A cmdlet can have multiple aliases
3. Some aliases are cmd command names under Windows, and some are Shell command names under Linux (it seems Microsoft is really considerate.)

If anyone wants to ask how to use aliases, well, I almost forgot about this question. Since it is called an alias, it must have replaced the original cmdlet, what do you think?

Regarding the alias of CmdLet in PowerShell, the editor will introduce it like this. I hope it will be helpful to beginners, thank you!

For more related articles on examples of using the Get-Alias ​​command to obtain cmdlet aliases in PowerShell, please pay attention to the PHP Chinese website!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn