View Single Post
Old 01. Jun 2009, 06:17 PM   #2 (permalink)
Senior Member
debtboy's Avatar
Join Date: May 2009
Location: ~/
Posts: 128

Originally Posted by Drigo View Post
So I copied my music to a hard drive, I formatted my PC and copied it back. Though it was unsuccesul, there were some zero byte files that were created. I manage to delete them but not the artwork.

So....basically I have many folders with just artwork that I want to delete... my question?

Can you please provide me a command to find folders under a an specific path where there is no *.mp3 files and delete them at the same time? Also, how can I create a file with the names of thes folders?

I hope you can help me!
but it's a script and not a single line.

  find $Your_Search_Path -maxdepth 1 -type d | while read folder
      mp3files=`$folder" | grep -e '.mp3' | wc -l`
      if [ "$folder" != "$Your_Search_Path" ]
        if [ "$mp3files" == "0" ]
          rm -r $folder
          echo "$folder" >> $Your_Search_Path/delete_log

Save the script and make it executable (chmod).
Put in your own search path
I'm assuming all your folders are sub-directories of your search path
and are only 1 layer deep.
I also assume you have permission over these files and directories.

Hope this helps.

In english:
shebang #!/bin/bash - how to execute
Set Your_Search_Path variable
Find directories current and 1 sub-directory deep
pipe that into read loop

Take directory name and pipe into grep looking for .mp3
pipe that into print newline count option and put that
number in the mp3files variable

Ignore your starting search folder, directory sub-directories only

If there are no mp3 files found delete the directory and contents

Write the deleted directory path to a delete_log logfile.

man pages will answer in detail the exact switch options used.

For those following the command line thread,
This is a shell script, nothing but a group of Bash commands!!

Last edited by debtboy; 01. Jun 2009 at 06:20 PM.
debtboy is offline   Reply With Quote