Microsoft Windows
lsof
安装
sudo pacman -S lsof
查找占用端口的 PID
lsof -i:8080
结束进程
kill -9 $PID
windows kill process
netstat
查看帮助
netstat /?
查找占用端口的 PID
netstat -ano | findstr "$port"
tasklist
查看帮助
tasklist /?
查找 PID 程序名
tasklist | findstr "$PID"
查找程序
tasklist | findstr "YunDetectService.exe"
taskkill
查看帮助
taskkill /?
结束进程映像名称
taskkill /f /t /im "YunDetectService.exe"
结束进程PID
taskkill /f /t /pid "$PID"
runas
cmd/powershell 使用管理员权限运行
runas ?
runas --help
runas /noprofile /user:administrator powershell
ExecutionPolicy
get-executionpolicy
set-executionpolicy remotesigned
New-Item
New-Item 别名 ni,新建文件/文件夹
get-help new-item
New-Item xxx -ItemType file
New-Item xxx -ItemType directory
vim in powershell
$profile 输出当前用户 powershell 启动时加载脚本
默认位置 C:\Users\leo\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1,不存在则新建
new-item -Path $profile -ItemType "file" -Force
编辑 C:\Users\leo\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
添加以下内容,重新打开 powershell 使生效
$VIMPATH="C:\Program Files (x86)\Vim\vim90\vim.exe"
Set-Alias vi $VIMPATH
Set-Alias vim $VIMPATH
character encoding
microsoft docs
Changing the default encoding
PowerShell has two default variables that can be used to change the default encoding behavior.
$PSDefaultParameterValues$OutputEncoding
Beginning in PowerShell 5.1, the redirection operators ( > and >>) call the Out-File cmdlet. Therefore, you can set the default encoding of them using the $PSDefaultParameterValues preference variable as shown in this example:
# vim $profile
$PSDefaultParameterValues['Out-File:Encoding'] = 'utf8'
Use the following statement to change the default encoding for all cmdlets that have the Encoding parameter.
# vim $profile
$PSDefaultParameterValues['*:Encoding'] = 'utf8'
Windows PowerShell 5.1 Encoding 参数支持以下值
Ascii使用 Ascii(7位)字符集BigEndianUnicode使用具有 big-endian 字节顺序的 UTF-16。BigEndianUTF32使用具有 big-endian 字节顺序的 UTF-32。Byte将一组字符编码为字节序列。Default使用与系统的活动代码页对应的编码, (通常为 ANSI) 。Oem使用与系统的当前 OEM 代码页对应的编码。String与 Unicode 相同。Unicode使用具有 little-endian 字节顺序的 UTF-16。Unknown与 Unicode 相同。UTF32使用具有 little-endian 字节顺序的 UTF-32。UTF7使用 UTF-7。UTF8将 UTF-8 (与 BOM) 配合使用。
通常,Windows PowerShell 默认使用 Unicode UTF-16LE 编码。
但是,与Windows PowerShell 中 cmdlet 使用的默认编码并不一致。
使用除 UTF7 之外 的任何 Unicode 编码始终会创建 BOM。
For cmdlets that write output to files:
Out-Fileand the redirection重定向 operators操作符>and>>createUTF-16LE, which notably differs fromSet-ContentandAdd-Content.New-ModuleManifestandExport-CliXmlalso createUTF-16LEfiles.- When the target file is empty or doesn’t exist,
Set-ContentandAdd-ContentuseDefaultencoding.Defaultis the encoding specified by the active system locale’sANSIlegacy code page. Export-CsvcreatesAsciifiles but uses different encoding when usingAppendparameter (see below).Export-PSSessioncreatesUTF-8files withBOMby default.New-Item -Type File -Valuecreates a BOM-less UTF-8 file.Send-MailMessageusesDefaultencoding by default.Start-TranscriptcreatesUtf8files with aBOM. When theAppendparameter is used, the encoding can be different (see below).
For commands that append to an existing file:
Out-File -Appendand the>>redirection operator make no attempt to match the encoding of the existing target file’s content. Instead, they use thedefaultencoding unless the Encoding parameter is used. You must use the files original原始的 encoding when appending content.- In the absence不存在 of an explicit明确的 Encoding parameter,
Add-Contentdetects侦察出 the existing encoding and automatically applies it to the new content. If the existing content has no BOM,DefaultANSI encoding is used. The behavior ofAdd-Contentis the same in PowerShell (v6 and higher) except the default encoding isUtf8. Export-Csv -Appendmatches the existing encoding when the target file contains a BOM. In the absence不存在 of a BOM, it usesUtf8encoding.Start-Transcript -Appendmatches the existing encoding of files that include a BOM. In the absence不存在 of a BOM, it defaults toAsciiencoding. This encoding can result in导致 data loss丢失 or character corruption腐蚀 when the data in the transcript转写本 contains multibyte多字节 characters.
For cmdlets that read string data in the absence不存在 of a BOM:
Get-ContentandImport-PowerShellDataFileuses theDefaultANSI encoding. ANSI is also what the PowerShell engine uses when it reads source code from files.Import-Csv,Import-CliXml, andSelect-Stringassume Utf8 in the absence不存在 of a BOM.