Created
January 11, 2015 18:37
-
-
Save bramp/24192fbc7ca87a29d2af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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