Skip to content

微软 PowerShell

Windows 安装 Git ,附带安装 Git Bash ,可以使用 sed 、diff 等命令。

Ubuntu 安装 PowerShell 。

sudo snap install powershell --classic

Ubuntu 卸载 PowerShell 。

sudo snap remove powershell

基于别名系统, PowerShell 相当程度上兼容 CMD 、Bash 。

Get-Alias
命令别名
Clear-Hostclear
Clear-Hostcls
Copy-Itemcp
Get-ChildItemls
Get-Contentcat
Get-Locationpwd
Move-Itemmv
Remove-Itemrm
Set-Locationcd
Write-Outputecho

清除终端输出,兼容 CMD 使用 cls ,兼容 Bash 使用 clear 。

cls
clear

给四个名称张三、李四、Alice、Bob ,排序方案有:

  • 存储,编码
  • 存储,两个字段,对存储空间有要求
  • 计算,代码,对计算性能有要求

为了示好各国政府、企业,早期微软选择了编码方案,进入互联网时代就有些不合时宜了。你做了一个网站,用户上传的文件编码各异。

Windows 命令行工具,有 cmd 、powershell 、pwsh 三种。

CMD 陈旧,有编码问题,但兼容性好。

Windows PowerShell ,非跨平台,命令为 powershell 。

PowerShell ,跨平台,命令为 pwsh 。Bash 面向文本,PowerShell 面向对象。

面向对象,功能强大,但复杂度提升。Get-Content 读取文件,默认返回数组,文本每行对应一个数组元素。

'Hello World
Hello Human' | Out-File a.txt

Get-Content a.txt
Hello World
Hello Human

查看数组元素个数。

(Get-Content a.txt).length
2

使用参数 -Raw 返回文本。将打印文本和打印数组做得差不多,微软真是出人才。

Get-Content a.txt -Raw
Hello World
Hello Human

PowerShell 窗口标题栏,鼠标右键,选择属性。

  • 选项,当前代码页等
  • 字体
  • 布局
  • 颜色,屏幕文字、屏幕背景、弹出文字、弹出窗口背景等
  • 终端

联系 math@baima.site