#!/bin/bash

set -eu
set -o pipefail

function invalidate_cache
{
    sync
    sync
    sync
    echo 3 > /proc/sys/vm/drop_caches
}

directories="/movie /usr/local $(echo ~dstromberg/Sound)"

# If we use time and not /usr/bin/time, we get two different time commands:
# One the shell builtin, and one the external program.  So we use /usr/bin/time.

# intentionally not quoting $directories
for directory in $directories
do
    echo "$directory hierarchy statistics in bytes"
    find "$directory"/ -type f -print0 | xargs -0 du -sb | awk ' { print $1 } ' | stddev | sed 's/^/   /'

    echo "$directory" fdupes
    invalidate-cache
    /usr/bin/time fdupes -r "$directory"/ > /dev/null

    echo "$directory" equivs3e
    invalidate-cache
    find "$directory"/ -type f -print0 | /usr/bin/time equivs3e -0 > /dev/null

    echo
done