Gizmos Freeware Reviews  

Go Back   Gizmo's Freeware Forum > Freeware Forum > Linux

Reply
 
Thread Tools Display Modes
Old 01. Jun 2009, 05:20 AM   #1 (permalink)
Junior Member
 
Join Date: Jun 2009
Posts: 1
Default Linux Command to find some folders and delete them....

Hello,
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!
Drigo is offline   Reply With Quote
Old 01. Jun 2009, 06:17 PM   #2 (permalink)
Senior Member
 
debtboy's Avatar
 
Join Date: May 2009
Location: ~/
Posts: 128
Smile

Quote:
Originally Posted by Drigo View Post
Hello,
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!
Sure,
but it's a script and not a single line.

Code:
#!/bin/bash
Your_Search_Path="/home/dringo/music"
  find $Your_Search_Path -maxdepth 1 -type d | while read folder
    do
      mp3files=`$folder" | grep -e '.mp3' | wc -l`
      if [ "$folder" != "$Your_Search_Path" ]
      then
        if [ "$mp3files" == "0" ]
        then
          rm -r $folder
          echo "$folder" >> $Your_Search_Path/delete_log
        fi
      fi
    done



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
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT +1. The time now is 12:00 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.