Skip to content

Instantly share code, notes, and snippets.

@patrickkettner
Last active January 4, 2016 07:18
Show Gist options
  • Save patrickkettner/8587290 to your computer and use it in GitHub Desktop.
Save patrickkettner/8587290 to your computer and use it in GitHub Desktop.
#!/bin/bash
# "diff" two different directories, outputting the filesize difference between them.
#
# $ diffdir foo bar
# baz.js: 52b 56p - -4b
# ensure we are only dealing with two directories
if [[ "$#" -ne 2 || !( -d "$1" && -d "$2") ]]; then
echo "need to pass two valid directories";
exit 1
fi
FILES_TO_DIFF=$(/usr/bin/diff -qr "$1" "$2" | awk '{print $2}')
for file in $FILES_TO_DIFF; do
filename=$(basename $file);
file1="$1"/"$filename"
file2="$2"/"$filename"
file1size=$(du -k "$file1" | cut -f1)
file2size=$(du -k "$file2" | cut -f1)
echo $filename $file1size $file2size - $(expr $file1size - $file2size)
done;
@candid82
Copy link

du outputs in blocks, but stat -f "%z" does the trick (outputs in bytes)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment