LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-31-2009, 11:24 PM   #1
Drigo
Member
 
Registered: May 2009
Posts: 111

Rep: Reputation: 17
How to use find and remove folders and files


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!
 
Old 05-31-2009, 11:53 PM   #2
sutrannu
LQ Newbie
 
Registered: Nov 2007
Location: USA, Midwest
Distribution: ubuntu
Posts: 13

Rep: Reputation: 1
UPDATED

Put this code in a file and make it executable. (chmod a+x this_script.sh) This will find all the folders within the location it's saved & run from, and print the names of the folders that do not contain mp3 files. I've commented out the line that will delete the folders. If the list you get from this suits your needs, remove the "#" from line 4 and run it again. Be careful whenever you use rm.

Code:
#!/bin/bash
for f in `find . -type d`; do
  if [ -z "`find $f -iname '*.mp3'`" ]; then
    #rm -rf $f
    echo $f
  fi
done

Last edited by sutrannu; 06-01-2009 at 03:12 PM. Reason: To prevent deleting parent folders with children containing mp3s
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Find and remove 7 days before modified/created files neel.gurjar Linux - Software 2 05-14-2008 08:17 PM
remove ~ from all files and folders BoraX Linux - General 1 10-25-2006 07:58 PM
How to remove folders Gins Linux - General 7 08-15-2006 01:31 PM
Samba can create new files and folders but access denied in any new folders k.king Linux - Networking 2 01-15-2006 06:14 AM
unable to remove files/folders timsch75 Linux - Software 2 03-01-2004 11:01 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration