6

Tip #197   Zero files

Zero out files leaving directory and file sets in place - used for archival purposes.
/// bash script file: cdn (located in /usr/local/bin)
#!/bin/bash
#
# Cataboligne - zero a single file passed in argument 1, and make a log entry
#
cat /dev/null > "$1"
echo "zero $1" >> $HOME/.zero-log
/// end bash script

command line:
find  -wholename '*/*.[mM][pP][32cC]' -exec echo {}\; -exec cdn {} \;


This example zeros all mp2/mp3/mpc of any case anywhere under the current directory + sub directories and tells you what got zapped.

Do the same thing for all files in a directory from a file manager (such as rox) menu shortcut.
/// bash script file: xt-zerofiles (located in /usr/local/bin)
#!/bin/bash
#
# Cataboligne - zero all files in a directory structure with double logging
# and verify, called from rox sub menu
#
cd "$@"
echo "" > /tmp/.cont
xterm -geometry 70x1 -title 'Zero Caution!' -e 'read -p "zero files in $PWD: Y/N? " RSP;echo $RSP > /tmp/.cont'
RSP2=`cat /tmp/.cont`
if [[ "$RSP2" != "Y" && "$RSP2" != "Yes" && "$RSP2" != "y" ]]; then exit; fi;
echo >> $HOME/.zero-log-summary
echo >> $HOME/.zero-log        
echo $(date) " zero fn() = $PWD" >> $HOME/.zero-log-summary
echo "------------------------------" >> $HOME/.zero-log-summary
echo $(date) " zero fn() = $PWD" >> $HOME/.zero-log        
echo "------------------------------" >> $HOME/.zero-log        
find -type f -exec cdn {} \;
rm -f /tmp/.cont
echo >> $HOME/.zero-log-summary
echo >> $HOME/.zero-log
/// end bash script

The method of calling this script depends on the file manager. With rox you right click on a file (such as a directory) and select "Customize menu" on the selected file sub menu. A rox window pops open with all the menu items for that file type and you can then open rox /usr/local/bin and drag and drop a link for xt-zerofiles.
I recommend a link instead of a copy so if you update the script you dont have to figure out where you copied it. The custom menu is my single favorite rox feature.

The script pops open a small bash window to ask for verification due to the risk of running such a command arbitrarily. And yes, I keep two logs there, you could reduce it to the $HOME/.zero-log or even have no logging.

/// Cataboligne