Created
February 26, 2019 08:50
-
-
Save krisives/a700293ab305e651dfee4b546673bbd3 to your computer and use it in GitHub Desktop.
Shred files in Linux including directory names
This file contains hidden or 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
#!/usr/bin/env bash | |
if [ "$#" -ne 1 ]; then | |
echo "Usage: shred-all <dir>" | |
exit 1 | |
fi | |
dir=$1 | |
if [ ! -d "$dir" ]; then | |
echo "Must pass a directory" | |
exit 1 | |
fi | |
echo "Changing permissions" | |
chmod 777 -R "$dir" | |
echo "Deleting files" | |
find "$dir" -type f | { | |
while read line; do | |
shred "$line" -u | |
done | |
} | |
echo "Deleting directories with randomized names" | |
find "$dir" -depth -mindepth 1 -type d | { | |
while read line; do | |
name=$RANDOM$RANDOM$RANDOM$RANDOM | |
tmp="$dir/$name" | |
mv "$line" "$tmp" | |
rmdir "$tmp" | |
done | |
} | |
rmdir "$dir" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment