Skip to content

Instantly share code, notes, and snippets.

@bramp
Created January 11, 2015 18:37
Show Gist options
  • Save bramp/24192fbc7ca87a29d2af to your computer and use it in GitHub Desktop.
Save bramp/24192fbc7ca87a29d2af to your computer and use it in GitHub Desktop.
#!/bin/sh
# Finds fake files (e.g. those files which are 700mb big, but contain just zeros)
# by bramp.net 2015
#
if [ -z "$1" ]; then
echo "Usage: $0 <directory/files>"
echo "List files that are fakes"
return
fi
for path in "$@"
do
find "$path" -type f | while read file; do
if [ -s "$file" ]; then
# If file is non-zero bytes, check if the actual content of the file is all zeros
cmp "$file" /dev/zero -n `stat -c "%s" "$file"` -s;
if [ $? -eq 0 ]; then
echo "$file"
elif [ $? -eq 2 ]; then
echo Error reading "$file"
# else files are different, ignore
fi
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment