![]() |
|
|
#1 (permalink) |
|
Junior Member
Join Date: Jun 2009
Posts: 1
|
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! |
|
|
|
|
|
#2 (permalink) | |
|
Senior Member
Join Date: May 2009
Location: ~/
Posts: 127
|
Quote:
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. |
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|