Skip to content

Instantly share code, notes, and snippets.

@torbiak
Created August 14, 2019 04:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save torbiak/1ae116cabc8ed564e6c27d23dea4c90e to your computer and use it in GitHub Desktop.
Save torbiak/1ae116cabc8ed564e6c27d23dea4c90e to your computer and use it in GitHub Desktop.
#!/bin/bash
usage='usage taketilcap [-h|--help] <capacity>
-h Show help
Filter newline-delimited filenames provided on stdin'
[[ $# -lt 1 ]] && {
echo "$usage"
exit 1
}
case "$1" in
-h|--help) echo "$usage"; exit 0;;
esac
cap=$1
xargs -d '\n' stat --printf "%W\034%s\034%n\n" \
| sort -k 1n \
| gawk -v cap=$(numfmt --from=si "${cap^^}") '
BEGIN {
FS = "\034"
# Field indexes
size = 2
name = 3
}
{
cap -= $(size)
if (cap < 0) {exit 0}
print $(name)
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment