Created
October 21, 2011 19:23
-
-
Save jwood/1304693 to your computer and use it in GitHub Desktop.
Slowly delete a file by truncating it by a small amount every half second until the file is eventually deleted
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/bash | |
# | |
# DESCRIPTION | |
# Slowly delete a file by truncating it by a small amount every half second | |
# until the file is eventually deleted. This should prevent the system from | |
# freaking out when attempting to delete a single, large file. | |
# | |
# USAGE | |
# fade.sh <file> | |
# | |
export TRUNCATE_AMOUNT=10485760 # 10 MB | |
export FILE=$1 | |
export FILESIZE=$(stat -c%s "$FILE") | |
while [ $FILESIZE -gt $TRUNCATE_AMOUNT ]; do | |
perl -e 'truncate($ENV{'FILE'}, $ENV{'FILESIZE'}-$ENV{'TRUNCATE_AMOUNT'})' | |
sleep 0.5 | |
export FILESIZE=$(stat -c%s "$FILE") | |
done | |
rm $FILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment