PDA

View Full Version : cleanup script



vixducis
May 28th, 2009, 04:23 PM
Hi,

To come right to the point: I need a script that deletes every file that doesn't have flac as extension and then deletes all the empty folders. I already read a file about shell scripting, and i learned the basics, but i just can't find a good solution. Can somebody make it or give me some hints?

Thanks,
Vixducis

ghostdog74
May 28th, 2009, 05:39 PM
check out the find command. man find


find /path -type f ! -name "*.flac" <continue>

johnl
May 28th, 2009, 05:40 PM
Hi,

here's a hint.

The following will give you a list of all files in "$DIR" that do not have ".flac" in their names (case insensitive):



find "$DIR" -type f | grep -i -v ".flac" |
while read file ; do
echo "$file"
done

johnl
May 28th, 2009, 05:45 PM
check out the find command. man find


find /path -type f ! -name "*.flac" <continue>


I swear I looked for a 'not' operator to find. Thanks for posting this, I learned something :)

vixducis
May 28th, 2009, 08:10 PM
Since there will be a maximum of 3 levels of subdirectories, i made this code (probably can be more efficient with a loop checking if there are empty subdirectories. It works, thanks for your help.


find . -type f ! -name '*.flac' -exec rm -f {} \;
find . -type d -empty -exec rm -rf {} \;
find . -type d -empty -exec rm -rf {} \;
find . -type d -empty -exec rm -rf {} \;