diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-08-09 17:15:40 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-08-09 17:20:10 +1200 |
commit | 9fb350dc7c8cc5259ef24e0cb097031179fab1d6 (patch) | |
tree | 839dd0b8ee3f5323b1cd6aefa22b605b99437d62 /bin/dub | |
parent | Mention nosls/sls flags in slsf(1) man page (diff) | |
download | dotfiles-9fb350dc7c8cc5259ef24e0cb097031179fab1d6.tar.gz dotfiles-9fb350dc7c8cc5259ef24e0cb097031179fab1d6.zip |
Improve commenting/exit handling in binscripts
Diffstat (limited to 'bin/dub')
-rwxr-xr-x | bin/dub | 21 |
1 files changed, 20 insertions, 1 deletions
@@ -1,13 +1,32 @@ #!/bin/sh # List the biggest files in a directory -dir=$1 lines=${2:-10} + +# First optional argument is the directory, defaulting to the +# current dir; second optional argument is the number of files to +# show, defaulting to 20 +dir=${1:-.} lines=${2:-10} + +# Enter the target dir or bail cd -- "$dir" || exit + +# Add files matching glob, shift them off if unexpanded (first and +# only entry doesn't exist) set -- * [ -e "$1" ] || shift + +# Add dot files, shift off the "." and ".." entries (sh(1) +# implementations seem to vary on whether they include these) set -- .* "$@" [ -e "$1" ] || shift [ "$1" = . ] && shift [ "$1" = .. ] && shift + +# Run du(1) with POSIX compatible flags -k for kilobyte unit and +# -s for total over the arguments du -ks -- "$@" | + +# Sort the first field (the sizes) numerically, in reverse sort -k1nr | + +# Limit the output to the given number of lines sed "$lines"q |