Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
So I have a bunch of mp3's in my flac folders and I want to delete them, but I'm more interested in finding a way to remove them through the commandline folder-recursively rather than having to cd to each directory and type rm .*mp3 each time.
You can try using the find command, but be careful. Do a test run first.
> find -name "*.mp3"
This will simply print the list of files "find" finds to standard output. If you have a lot of files to delete and you want to inspect them closely, redirect the above command into a text file for closer inspection:
> find -name "*.mp3" > output.txt
To delete the files "find" finds, run this command:
> find -name "*.mp3" -delete
If you have several subdirectories of files and you want find to delete mp3s in some subdirectories and not others, the easiest thing to do is to switch to the base directory. E.g., If you have mp3s in these areas:
If you want to delete mp3s in the music directory and its subdirectories but not in the audio directory or its subdirectories, simply change to the music directory. Do a test run first. Be very careful about find + delete usage because you could easily wipe out what you want to keep. Make backups before if you want.
So far, cseanburns has the best suggestion. Using rm will not just remove .mp3 but any file extension like .jpg .doc etc., not sure why but I know from experience. Find is the better command to use but the suggested command above needs refinement. Change into the parent directory.
Code:
find . -name "*.mp3" -delete
The (.) says to look in the current directory and all sub-directories.
EDIT: Where are all these "flac" folders?
Last edited by Junior Hacker; 04-23-2007 at 02:07 AM.
The GNU version of find doesn't need the period (unlike the
one that ships with Solaris), starting from the current working
directory is the default behaviour.
That is so powerful!
It took me a while to get some time to do upkeeping on my computer, but I'm so glad you showed me how to do that. It works perfectly, as outlined by cseanburns & Junior Hacker.
The GNU version of find doesn't need the period (unlike the
one that ships with Solaris), starting from the current working
directory is the default behaviour.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.