Last active
March 9, 2016 15:06
-
-
Save damc-dev/ffa16f087eb849b958d6 to your computer and use it in GitHub Desktop.
Print the open log files and their sizes in human readable format
This file contains hidden or 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/sh | |
/usr/sbin/lsof +D /logs -s 2>/dev/null | sort -k 7 -g -r | while read x; do | |
size=`echo $x | awk '{print $7}'` | |
file=`echo $x | awk '{print $9}'` | |
SIZE=`echo $size | awk 'function human(x) { | |
s=" B KiB MiB GiB TiB EiB PiB YiB ZiB" | |
while (x>=1024 && length(s)>1) | |
{x/=1024; s=substr(s,5)} | |
s=substr(s,1,4) | |
xf=(s==" B ")?"%5d ":"%8.2f" | |
return sprintf( xf"%s\n", x, s) | |
} | |
{gsub(/^[0-9]+/, human($1)); print}'` | |
echo "$SIZE $file" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment