From b111bd12e33f67ebaa31d83ac3687b3150499a68 Mon Sep 17 00:00:00 2001 From: cmdln Date: Sun, 21 Aug 2011 15:48:31 -0400 Subject: [PATCH] Smarten clean up to delete raw audio, feeds except for last few each. --- cleanup.bash | 54 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/cleanup.bash b/cleanup.bash index fc48c6e..b310132 100755 --- a/cleanup.bash +++ b/cleanup.bash @@ -1,6 +1,50 @@ #!/bin/bash -rm *.mp3 -rm *.chapters.txt -rm *.m4a -rm *.ogg -rm *.flac +prefix=$1 + +if [ -z $prefix ] +then + echo "Must specific a prefix." + exit 1 +fi + +function clean_old() { + prefix=$1 + ext=$2 + to_keep=$3 + ls $prefix*$ext 1> /dev/null 2>&1 + clean=$? + count=0 + if [ 0 -eq $clean ] + then + for file in $(ls -r $prefix*$ext) + do + if [ $count -lt $to_keep ] + then + count=$((count + 1)) + else + rm $file + fi + done + fi +} + +function clean_ext() { + ls $1*$2 1> /dev/null 2>&1 + clean=$? + if [ 0 -eq $clean ] + then + rm $1*$2 + fi +} + +clean_old $prefix "wav" 2 +clean_old $prefix "mp3.xml.*" 1 +clean_old $prefix "m4a.xml.*" 1 +clean_old $prefix "ogg.xml.*" 1 + +clean_ext $prefix "mp3" +clean_ext $prefix "chapters.txt" +clean_ext $prefix "m4a" +clean_ext $prefix "ogg" +clean_ext $prefix "flac" +