Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save einsteinx2/14a0e865295cf66aa9a9bf1a8e46ee49 to your computer and use it in GitHub Desktop.
Save einsteinx2/14a0e865295cf66aa9a9bf1a8e46ee49 to your computer and use it in GitHub Desktop.
monitorio - Bash function to monitor the size of a file on disk
# Show write speed for file or directory
# Optional second parameter to set the check interval in seconds, defaults to 20
monitorio () {
target="$1"
interval=${2:-"20"}
echo -e "Checking every ${interval} seconds"
size=$(du -ks "$target" | awk '{print $1}')
firstrun="1"
echo ""
while [ 1 ]; do
prevsize=$size
size=$(du -ks "$target" | awk '{print $1}')
#size=$(ls -l "$1" | awk '{print $5/1024}')
kb=$((${size} - ${prevsize}))
kbmin=$((${kb}* (60/${interval}) ))
kbsec=$((${kbmin}/60))
kbhour=$((${kbmin}*60))
if [ $firstrun -ne 1 ]; then
echo -e "\e[1A $target changed ${kb}KB ${kbsec}KB/sec ${kbmin}KB/min ${kbhour}KB/hour size: ${size}KB"
fi
firstrun=0
sleep $interval
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment