Skip to content

Instantly share code, notes, and snippets.

@rojenzaman
Created June 9, 2021 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rojenzaman/a046667549f5e6547d2e6b32132d376d to your computer and use it in GitHub Desktop.
Save rojenzaman/a046667549f5e6547d2e6b32132d376d to your computer and use it in GitHub Desktop.
BASH script to write zeros to file before remove | Use for non-secure HDD
#!/bin/bash
# use find exec to remove multiple files:
# find path/to/dir -exec ./rmzero {} \;
if [ "$#" -lt 1 ]; then
echo "./`basename $0` <file>";
exit 1;
fi
function load() { FILE="$(realpath $1)" ; MB_COUNT="$(du -m $FILE | awk '{print $1}')" ; }
function main() { dd if=/dev/zero of="$FILE" bs=1M count=$MB_COUNT ; rm $FILE ; }
load "$@" &>/dev/null
if [ -f "$FILE" ]; then
main &>/dev/null &
else
echo "$FILE is not a file."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment