PowerShell学习笔记

文件批量改后缀

1
dir * | foreach { Rename-Item $_ -NewName ($_.BaseName+”.mp4”)  }

解除端口占用

首先找到占用端口的进程,然后终止进程:

1
2
netstat -nao | findstr "5554" 	# 假设5554端口被占用
taskkill -pid 5076 -f # 结束占用进程

查找文件

如果不指定Path则默认查找当前目录。查找支持正则表达式。

1
Get-ChildItem -Path C:\Users\JohnDoe -Filter *.txt -Recurse

批量git push

1
2
3
4
5
6
7
Get-ChildItem -Directory | ForEach-Object {
$gitDir = Join-Path $_.FullName ".git"
if (Test-Path $gitDir) {
Set-Location $_.FullName
git push
}
}
作者

xeonds

发布于

2022-06-05

更新于

2024-05-13

许可协议

评论