Created
April 5, 2019 20:09
-
-
Save cjblocker/92032ad4ba4c9fe168121cea8b6c08d4 to your computer and use it in GitHub Desktop.
Print disk usage of all files and directories (ducks) with the colors of ls (for macOS).
This file contains 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
#!/bin/bash | |
# Don't glob . and .. and don't ignore .files | |
export GLOBIGNORE=".:.." | |
# Old ducks with no color, sorted ascending with at most the 50 largest | |
#alias ducks='du -cksh * | sort -h | tail -n 50' | |
# ducks with color from ls, sorted ascending with at most the 50 largest | |
alias ducks="paste -d' ' <(du -cksh * | cut -f1) <(CLICOLOR_FORCE=1 ls -1d * && echo total) | sort -h | tail -n 50" | |
# paste creates columns from the inputs with ' ' as the column delimiter | |
# du -cksh * prints disk usage with a total and human readable sizes | |
# cut -f1 cuts the first field of every line | |
# CLICOLOR_FORCE=1 force ls on macOS to output color even if not directed to a terminal (try unbuffer for linux) | |
# echo total adds one more line of names for the total | |
# sort -h sorts the lines in human understandable numeric form (i.e. 200MB < 1G). Add -r for the opposite order. | |
# tail -n 50 keeps only the last 50 lines | |
# Refs | |
# http://mywiki.wooledge.org/ParsingLs | |
# https://unix.stackexchange.com/questions/1168/how-to-glob-every-hidden-file-except-current-and-parent-directory | |
# https://superuser.com/questions/352697/preserve-colors-while-piping-to-tee |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment