Skip to content

Instantly share code, notes, and snippets.

@jwood
Created October 21, 2011 19:23
Show Gist options
  • Save jwood/1304693 to your computer and use it in GitHub Desktop.
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
#!/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