#Set-Alias ls Get-ChildItem
function ll {
Get-ChildItem | Sort-Object Name
}
# sort ascending (ls -lrt)
function lt {
Get-ChildItem | Sort-Object LastWriteTime
}
# sort descending (ls -lr)
function ltd {
Get-ChildItem | Sort-Object LastWriteTime -Descending
}
# Long listing with human-readable sizes sorted by Name
function lh {
Get-ChildItem | Sort-Object Name |
Format-Table @{Label="Date";Expression={$_.LastWriteTime}},
@{Label="Size";Expression={
if ($_.PSIsContainer) { "<DIR>" }
elseif ($_.Length -ge 1GB) { "{0:N1} GB" -f ($_.Length / 1GB) }
elseif ($_.Length -ge 1MB) { "{0:N1} MB" -f ($_.Length / 1MB) }
elseif ($_.Length -ge 1KB) { "{0:N1} KB" -f ($_.Length / 1KB) }
else { "$($_.Length) B" }
};Align="Right"},
@{Label="Name";Expression={$_.Name}} -AutoSize
}
# Long listing with human-readable sizes sorted by Name
function lht {
Get-ChildItem | Sort-Object LastWriteTime |
Format-Table @{Label="Date";Expression={$_.LastWriteTime}},
@{Label="Size";Expression={
if ($_.PSIsContainer) { "<DIR>" }
elseif ($_.Length -ge 1GB) { "{0:N1} GB" -f ($_.Length / 1GB) }
elseif ($_.Length -ge 1MB) { "{0:N1} MB" -f ($_.Length / 1MB) }
elseif ($_.Length -ge 1KB) { "{0:N1} KB" -f ($_.Length / 1KB) }
else { "$($_.Length) B" }
};Align="Right"},
@{Label="Name";Expression={$_.Name}} -AutoSize
}
# grep equivalent
function grep {
param(
[string]$Pattern,
[string]$Path = "."
)
Get-ChildItem -Recurse -Path $Path -File |
Select-String -Pattern $Pattern
}