#!/bin/sh # The MIT License (MIT) # # Copyright © 2020-2025 pacman64 # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the “Software”), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. # sfs [options...] [filenames...] # # Show File Sizes, using my other scripts `nn` and `cext`. case "$1" in -h|--h|-help|--help) awk '/^# +sfs /, /^$/ { gsub(/^# ?/, ""); print }' "$0" exit 0 ;; esac # turn arg-list into single-item lines printf "%s\n" "$@" | # calculate file-sizes, and reverse-sort results xargs -d '\n' wc -c | sort -rn | # add/realign fields to improve legibility awk ' # start output with a header-like line, and add a MiB field BEGIN { printf "%6s %10s %8s name\n", "n", "bytes", "MiB"; fflush() } # make table breathe with empty lines, so tall outputs are readable (NR - 1) % 5 == 1 && NR > 1 { print "" } # emit regular output lines { printf "%6d %10d %8.2f ", NR - 1, $1, $1 / 1048576 # first field is likely space-padded gsub(/^ */, "") # slice line after the first field, as filepaths can have spaces $0 = substr($0, length($1) + 1) # first field is likely space-padded gsub(/^ /, "") printf "%s\n", $0; fflush() } ' | # make zeros in the MiB field stand out with a special color awk ' { gsub(/ 00*\.00* /, "\x1b[38;2;135;135;175m&\x1b[0m") print; fflush() } ' | # make numbers nice, alternating styles along 3-digit groups nn --gray | # color-code file extensions cext | # make result interactively browsable less -JMKiCRS