Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 06-01-2009, 12:24 AM   #1
Registered: Jun 2009
Posts: 111

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

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 06-01-2009, 12:53 AM   #2
LQ Newbie
Registered: Nov 2007
Location: USA, Midwest
Distribution: ubuntu
Posts: 13

Rep: Reputation: 1

Put this code in a file and make it executable. (chmod a+x 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.

for f in `find . -type d`; do
  if [ -z "`find $f -iname '*.mp3'`" ]; then
    #rm -rf $f
    echo $f

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 09:17 PM
remove ~ from all files and folders BoraX Linux - General 1 10-25-2006 08:58 PM
How to remove folders Gins Linux - General 7 08-15-2006 02:31 PM
Samba can create new files and folders but access denied in any new folders k.king Linux - Networking 2 01-15-2006 07:14 AM
unable to remove files/folders timsch75 Linux - Software 2 03-01-2004 12:01 PM > Forums > Linux Forums > Linux - Newbie

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

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