Skip to content

Instantly share code, notes, and snippets.

@derpeter
Created October 15, 2017 12:21
Show Gist options
  • Save derpeter/bd711ba6a8b9e58587598b3335988dcd to your computer and use it in GitHub Desktop.
Save derpeter/bd711ba6a8b9e58587598b3335988dcd to your computer and use it in GitHub Desktop.
compare the size of files with the same filename in two directorys
#!/bin/bash
DIR1=~/bar/
DIR2=~/foo/
SIZE1=0
SIZE2=0
for file in $DIR1*; do
file2=$DIR2$(basename "$file")
if [[ -f $file ]] && [[ -f $file2 ]]; then
((S1=$(stat -c%s "$file")))
((S2=$(stat -c%s "$file2")))
echo $(basename "$file") size 1 $(($S1/1024/1024)) MB size 2 $((S2/1024/1024)) MB
((SIZE1+=$S1))
((SIZE2+=$S2))
fi
done
echo "size of files in" $DIR1: $((SIZE1/1024/1024/1024)) GB
echo "size of files in" $DIR2: $((SIZE2/1024/1024/1024)) GB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment