powershell相关

查看别名

  • 使用Get-Command查看Alias的命令: Get-Command -CommandType Alias
  • 查看此Session中已经设定的所有别名:Get-Aliasgal
  • 查看某别名的原命令,如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 CmdletPowerShell 别名
cdchdircdSet-Locationslcdchdir
clsclearClear-Hostcls clear
copycpCopy-Itemcpicpcopy
deleraserdrmdirrmRemove-Itemrideleraserdrmrmdir
dirlsGet-ChildItemgcidirls
echoechoWrite-Outputwrite echo
mdmkdirNew-Itemni
movemvMove-Itemmimovemi
popdpopdPop-Locationpopd
pwdGet-Locationglpwd
pushdpushdPush-Locationpushd
renmvRename-Itemrniren
typecatGet-Contentgccattype

 备注

此表中的别名特定于 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。

作者: Mr.Tang

伯虎

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

80  ⁄    =  8