Last active
January 12, 2024 07:49
-
-
Save henno/4bdd84b317616edce0b70ae7b30ba339 to your computer and use it in GitHub Desktop.
ll for PowerShell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # First type notepad $profile in powershell | |
| # Then paste the following code in the notepad and save it | |
| # Then restart the powershell or type . $profile in powershell | |
| # Then type ll in powershell to see the linux style directory listing | |
| function Get-LinuxStyleChildItem { | |
| Get-ChildItem -Force | ForEach-Object { | |
| $item = $_ | |
| $size = if ($item.Length -ge 1GB) { | |
| "{0:N2} GB" -f ($item.Length / 1GB) | |
| } elseif ($item.Length -ge 1MB) { | |
| "{0:N2} MB" -f ($item.Length / 1MB) | |
| } elseif ($item.Length -ge 1KB) { | |
| "{0:N2} KB" -f ($item.Length / 1KB) | |
| } else { | |
| "$($item.Length) B" | |
| } | |
| $mode = if ($item.PSIsContainer) { "d" } else { "-" } | |
| $mode += if ($item.Attributes -match 'ReadOnly') { "r" } else { "-" } | |
| $mode += if ($item.Attributes -match 'Hidden') { "h" } else { "-" } | |
| $mode += if ($item.Attributes -match 'System') { "s" } else { "-" } | |
| $mode += if ($item.Attributes -match 'Archive') { "a" } else { "-" } | |
| $lastWriteTime = $item.LastWriteTime.ToString("dd.MM.yyyy HH:mm:ss") | |
| # Determine the color | |
| $color = "Gray" # Default color for files | |
| if ($item.PSIsContainer) { | |
| $color = "Blue" # Color for directories | |
| } elseif ($item.LinkType) { | |
| $color = "Cyan" # Color for links | |
| } | |
| # Write the line with color | |
| Write-Host ("{0,10} {1,10} {2,20} {3,-20}" -f $mode, $size, $lastWriteTime, $item.Name) -ForegroundColor $color | |
| } | |
| } | |
| Set-Alias -Name ll -Value Get-LinuxStyleChildItem |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment