Guest User

Untitled

a guest
Nov 19th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. # List directory contents by size, for items that are larger than 1M.
  2. #
  3. # $1 directory, optional, defaults to $PWD
  4. # $2 traversal depth, optional, defaults to 1, requires numeric value
  5. # $3 sort order, optional, defaults to ascending unless r is specified
  6.  
  7. list_by_size () {
  8. dir=${1:-"$PWD"}
  9. depth=${2:-1}
  10. sort=${3:-""}
  11.  
  12. if [[ -d "${dir}" && $depth -gt 0 && (-z "${sort}"
  13. || "${sort}" = "r") ]]; then
  14. du -d$depth "$dir" \
  15. | sort -k1 -n"$sort" \
  16. | awk '{M = 1024; G = 1024^2; if ($1 >= G) {print $1/G"G\t"$2}
  17. else if ($1 >= M) {print $1/M"M\t"$2}}' \
  18. | column -t;
  19. else
  20. echo "list_by_size usage: list_files_by_size dirname depth" >&2;
  21. fi
  22. }
Add Comment
Please, Sign In to add comment