#!/bin/sh # Trash.sh # (c) Steve Parker 2005 # No warranties, no expectations that this script will do anything in particular. # Do not depend upon this script to do anything at all, good or bad. # Let me say this again in another way: This script does stuff. It may lose data, it may not. # I don't guarantee it in any way. # # The idea is that it does the following: # - Write crap to a file # - Rename the file to something crap # - If the file is part of a directory to be trashed, rm -rf the directory getcrapfile() { head -c $1 /dev/urandom } getcrap() { head -$1 /dev/urandom |cut -c1| tr [:blank:] '_' | tr '\n' '_' | tr '/' '_' | tr ';' '_' | tr '"' '_' | tr "'" '_' } trashfile() { ls -l $1 | awk '{ print $5,$8 }' | while read size name do echo "Trashing file : $name (size $size) ..." getcrapfile $size > $name j=`dirname $name` crapname=`getcrap 10` #echo "Renaming it to $crapname" echo "Renaming it to something strange ..." mv -- "${name}" ${j}/${crapname} done } trashtree() { echo "Trashing tree $1..." P=`pwd` cd $1 find . -type f -print | while read name do trashfile $name done cd $P echo "rm -rf $1 " } poprand() { while : do ls -R / >/dev/null 2>&1 done } ### Script Starts Here if [ "$?" -eq "0" ]; then echo "Usage: `basename $0` files/dirs to trash" exit 1 fi poprand & echo "This will trash any personal settings for the user." echo " *** THIS IS FOR REAL ***" echo "Do you REALLY wish to continue?" echo "CTRL-C NOW to cancel... you have 10 seconds." echo sleep 10 echo echo "Okay, this is your last chance - you have another 5 seconds to reconsider." echo sleep 5 echo echo "That's it, we're doing it. Well, we'll do it in five seconds. I really mean it this time." echo sleep 5 echo echo "Deleting personal files...." for i in $@ do if [ -d "$i" ]; then trashtree "$i" & else trashfile "$i" fi done