Wipe all mp3s and avis from the filesystem

So you want to run a script that removes all mp3 and avi files off the filesystem. One way (in bash) as below. Comment, suggestions and feedback are welcome 🙂 Using $EUID to check for root user, and $IFS to check for line breaks as the file names has spaces in them. IFS is saved to a temp variable, reset and then re-instated afterwards. C is the counter. Got two litte for loops in bash with backtick execution.

#!/bin/bash
echo "Malicious file type removal (mp3 and avi)";
echo "---------------------------------------";
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
echo "Updating database";
/usr/bin/updatedb
echo "Done updating database";
echo "Removing mp3 files";
SAVEIFS=$IFS
IFS='\
'
C=0;
for f in `locate -b -e .mp3`;
do
rm "${f}";
C=$(( $C + 1))
done;
echo " Total of $C mp3 files deleted";
echo " Done removing mp3 files";

echo "Removing avi files";
C=0;
for f in `locate -b -e .avi`;
do
rm "${f}";
C=$(( $C + 1))
done;
echo " Total of $C avi files deleted";
echo "Done.";
IFS=$SAVEIFS

Leave a Reply

Your email address will not be published. Required fields are marked *