powershell使用ll、head、tail等linux命令
最近在windows系统上办公比较多,想使用linux上经常用到的ll、head、tail等命令。发现可以通过修改powershell的配置文件来实现。具体地,一般需要修改以下路径的配置文件,没有的话就在该路径下创建一个。
配置文件路径:"C:\Users\你的用户名\Documents\WindowsPowerShell\profile.ps1”
$env:LESSCHARSET='utf-8'
# 1.快速powershell中cd到常用目录
function my_app {cd C:\Users\你的用户名\Desktop\workspace\apps}
# 2.powershell中执行ll命令
function Get-ChildItemUnix {
Get-ChildItem $Args[0] |
Format-Table Mode, @{N='Owner';E={(Get-Acl $_.FullName).Owner}}, Length, LastWriteTime, @{N='Name';E={if($_.Target) {$_.Name+' -> '+$_.Target} else {$_.Name}}}
}
New-Alias ll Get-ChildItemUnix
# 3.powershell中执行head命令
Function Get-Head {
param(
[Parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[string]$Path,
[Parameter(Position = 1)]
[int]$n = 10
)
Get-Content -Path $Path -TotalCount $n
}
Set-Alias -Name head -Value Get-Head
# 4.powershell中执行tail命令
Function Get-Tail {
param(
[Parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[string]$Path,
[Parameter(Position = 1)]
[int]$n = 10
)
Get-Content -Path $Path -Tail $n
}
Set-Alias -Name tail -Value Get-Tail
#Set-Alias -Name head -Value Get-Content -First 10
#Set-Alias -Name tail -Value { Get-Content -Tail 10 }