/ Published in: Bash
A tiny secure deletion tool...
Example:
$ karm.sh image1.jpg
karming image1.jpg... [OK]
$ karm.sh /etc/passwd
karming /etc/passwd... [ERR]:
/etc/passwd not karmed. Are you the owner?
Example:
$ karm.sh image1.jpg
karming image1.jpg... [OK]
$ karm.sh /etc/passwd
karming /etc/passwd... [ERR]:
/etc/passwd not karmed. Are you the owner?
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#!/usr/bin/env bash # karm.sh # A tiny secure deletion tool # Uses dd, fsync and /dev/urandom to overwrite # a file twice with a random data stream and delete it. # @_ksaver, Feb 2010. # Licence: Public Domain Code. # Use it with caution and under your own risk. # Not warranty provided at all. VERSION='0.4' function karm(){ # Gets file name from $1 FILE="$1" # Gets file size. SIZE=$(/usr/bin/du -k "$FILE") COUNT=${SIZE%"$FILE"*} # check if urandom exists if [ -e '/dev/urandom' ] then RANDD='/dev/urandom' else RANDD='/dev/random' fi # Send random stream to file... /bin/dd if=$RANDD of="$FILE" bs=1k count=$COUNT &> /dev/null # If data was successfuly written... if [ $? = 0 ] then # forces writing of cached file to physical storage... (/usr/bin/env fsync "$FILE" &> /dev/null && return 0) \ || ( sync && return 0) else return 1 fi } function kdelete(){ # unlink the karmed file's inode... /bin/rm "$1" > /dev/null || return 1 } # _main_ # if not arguments were given... if [ -z "$1" ] then echo -e "\tkarm $VERSION: Secure deleting tool." echo -e "\tSyntaxis: $0 <File_to_delete>" exit 1 else FILE="$1" # If file exists if [ -f "$FILE" ] then echo -n "karming $FILE... " karm "$FILE" && karm "$FILE" && kdelete "$FILE" if [ $? = 0 ] then # this far, everything has gone ok... echo " [OK]" exit 0 else # May be you are not the owner of file echo -e "[ERR]:\n$FILE not karmed. Are you the owner?" exit 1 fi else # File doesn't exist... echo "[ERR] $0: Is $FILE a valid file?" exit 1 fi fi # EOF