Created
August 14, 2019 04:05
-
-
Save torbiak/1ae116cabc8ed564e6c27d23dea4c90e to your computer and use it in GitHub Desktop.
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 | |
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