4

Is there a way to monitor and log folder size in Bash/Ubuntu? I'm running some computations and I need to know how much disk space they need. They may create some temporary folders for a few minutes/hours.

In fact, I need only a peak size of this folder.

Giacomo1968
  • 58,727
AleX
  • 41

3 Answers3

2

While this has been long dead, I thought I might add an inotify based approach to the mix, rather than a time or sleep based one.

If a file gets written & closed, or if a file gets removed, trigger a du and log it with a time-stamp and the size in MB.

If you remove one of the qs in -qq you get to see the events and correlated filenames in the terminal the script is running in.

#!/bin/sh
while inotifywait -qq -r -e close_write -e delete /path/to/dir; do
  (/usr/bin/echo -en "$(date '+%Y%m%d%H%M%S')\t";du -sm|cut -f1) >> ~/du.log
done

After your code is finished, just run this:

sort -k2,2n ~/du.log|tail -n 1

And you're done.

Note: If dir in the script above happens to be your home, you obviously need to put the log somewhere else.

Giacomo1968
  • 58,727
tink
  • 2,059
1

watch is not created to produce log-files.

What you search is something like:

#!/bin/bash
while :
do
    du -skh /your-directory
    echo "Press [CTRL+C] to stop.."
    sleep 1
done
Giacomo1968
  • 58,727
Bodo
  • 81
0

You might try something like:

watch "du -skh /your-directory"

If size/number of file increases set interval with -n to much greater than 2 sec.

Giacomo1968
  • 58,727
Bodo
  • 81