1.) Deletes all files that are not .mp3 inside a folder(searches inside all sub-folders)
2.) Deletes any empty directories (not essential)
Short and sweet.Any solution to that would be great.
Thanks in advance
Saj
1.) Deletes all files that are not .mp3 inside a folder(searches inside all sub-folders)
2.) Deletes any empty directories (not essential)
Short and sweet.Any solution to that would be great.
Thanks in advance
Saj
Ubuntu User Since 6.06 - "Here To Help"
Ubuntu Beta Tester Since 6.10 - "We have the problems so you don't have too."
--------------------------------------------------
Linux Registered User: 452642 Ubuntu Registered User: 17365
Not sure about the mp3s, guess you'd have to play around with find. For more details run
As for the empty foldersCode:man find
When I tried it, it was returning some errors, but worked anywaysCode:find <path> -empty -type d -exec rm -r '{}' \;
EDIT: Sorry just re read what you said. Anything thats NOT an MP3. My post will remove all mp3's.
Not tested but something like:
That should work. Just be very careful with the rm command.Code:cd {folder of choice} rm *.mp3
I just tried it with a made up extension of .abc on my desktop and it worked fine.
Last edited by Sub101; October 16th, 2008 at 11:02 PM.
I assume there is not a great deal of file extensions in your folder could you not remove each extension one at a time? And to include sub-folders the -r option would work.
For 1. I think this should work (just tested it):
By popular demand:Code:rm -r *[^.mp3]
edit: be warned that this command will do what the original poster wanted it to do - delete all files which don't end with ".mp3" from the active folder and all subfolders.
Last edited by Idefix82; October 18th, 2008 at 01:19 PM.
Helping people crawl out of their Windoze...
Please read THIS before asking if Anti-Virus and Firewalls are needed.
Obviously.
Helping people crawl out of their Windoze...
Please read THIS before asking if Anti-Virus and Firewalls are needed.
Here is a another way to do it,2 more steps but gives you more of an idea of what you are actually deleting...
Open a terminal and cd into the directory with your mp3 files (I'll use $HOME/music as an example)
next run...cd $HOME/music
(should list all the files that are not .mp3)find . \( \! -name "*\.mp3" -type f \) -print0
next run...
If the files listed are what you want gone go ahead and run...find . \( \! -name "*\.mp3" -type f \) -print0 | xargs -0 echo
Files should be gone and you may have a little more assurance that nothing you wanted was deleted by mistake.find . \( \! -name "*\.mp3" -type f \) -print0 | xargs -0 /bin/rm -f
Last edited by fenian; October 16th, 2008 at 11:58 PM.
Relax. It was pretty clear to me that a person with twice as many posts as me and advertising himself as Beta-tester in the signature is not a brand new user.
I really don't understand why you are having a go at me for answering his question. I am sure that it was clear to him that deleting recursively all files which do not satisfy some criterion can be dangerous if you are careless. Nobody on these forums has lost any files he didn't want to lose because of me and I have helped a fair few people, among other things to get rid of things they didn't want.
Next time, just read the posts properly.
Bookmarks