Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # List directory contents by size, for items that are larger than 1M.
- #
- # $1 directory, optional, defaults to $PWD
- # $2 traversal depth, optional, defaults to 1, requires numeric value
- # $3 sort order, optional, defaults to ascending unless r is specified
- list_by_size () {
- dir=${1:-"$PWD"}
- depth=${2:-1}
- sort=${3:-""}
- if [[ -d "${dir}" && $depth -gt 0 && (-z "${sort}"
- || "${sort}" = "r") ]]; then
- du -d$depth "$dir" \
- | sort -k1 -n"$sort" \
- | awk '{M = 1024; G = 1024^2; if ($1 >= G) {print $1/G"G\t"$2}
- else if ($1 >= M) {print $1/M"M\t"$2}}' \
- | column -t;
- else
- echo "list_by_size usage: list_files_by_size dirname depth" >&2;
- fi
- }
Add Comment
Please, Sign In to add comment