查看别名
- 使用Get-Command查看Alias的命令:
Get-Command -CommandType Alias - 查看此Session中已经设定的所有别名:
Get-Alias或gal - 查看某别名的原命令,如
ls的原命令:Get-Alias ls - 查看某原命令的别名,如
Get-ChildItem的别名:Get-Alias -Definition Get-ChildItem - 按属性获取别名:
Get-Alias | Where-Object {$_.Options -Match "ReadOnly"}
Windows 中的兼容性别名
PowerShell 具有多个别名,使 UNIX 和 cmd.exe 用户可以在 Windows 中使用熟悉的命令。 下表显示了常用命令、相关的 PowerShell cmdlet 和 PowerShell 别名:
| cmd.exe命令 | UNIX 命令 | PowerShell Cmdlet | PowerShell 别名 |
|---|---|---|---|
| cd、chdir | cd | Set-Location | sl、cd、chdir |
| cls | clear | Clear-Host | cls clear |
| copy | cp | Copy-Item | cpi、cp、copy |
| del、erase、rd、rmdir | rm | Remove-Item | ri、del、erase、rd、rm、rmdir |
| dir | ls | Get-ChildItem | gci、dir、ls |
| echo | echo | Write-Output | write echo |
| md | mkdir | New-Item | ni |
| move | mv | Move-Item | mi、move、mi |
| popd | popd | Pop-Location | popd |
| pwd | Get-Location | gl、pwd | |
| pushd | pushd | Push-Location | pushd |
| ren | mv | Rename-Item | rni、ren |
| type | cat | Get-Content | gc、cat、type |
备注
此表中的别名特定于 Windows。 某些别名在其他平台上不可用。 这是为了使本机命令能够在 PowerShell 会话中工作。 例如,未在 macOS 或 Linux 上将 ls 定义为 PowerShell 别名,以便运行本机命令而不是 Get-ChildItem。
Windows 下GUI编辑工具 PowerShell ISE
单击“开始”,选择“Windows PowerShell”,然后单击“Windows PowerShell ISE”。 或者,可以在任何命令外壳或“运行”框中键入内容。powershell_ise.exe
Linux下安装 powershell
如果你已安装 .NET Core SDK,则可以轻松地安装 PowerShell 作为 .NET 全局工具。
sh复制
dotnet tool install --global PowerShell
dotnet 工具安装程序将 ~/.dotnet/tools 添加到 PATH 环境变量中。 但是,当前运行的 shell 没有更新的 PATH。 应该可以通过键入 pwsh 从新 shell 启动 PowerShell。