rm *.foo through recursive directories
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.
I have tried rm -r *.mp3 but this doesn't work. Any ideas? |
man rm...
Mine shows rm -r and rm -R as recursive removes. Try -R if -r isn't working (for whatever reason), and try specifying the directory explicitly, i.e.: rm -R ./*.mp3 |
If you are in the directory then type:
Code:
rm -R * Code:
rm -R /this/is/my/directory/* EDIT: Sorry, I don't think my reply is what you need. I misunderstood what you were asking for. |
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: /home/user/music/ /home/user/music/bandname/ /home/user/audio/ /home/user/audio/personal/ 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. Hope that helps, sean |
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 EDIT: Where are all these "flac" folders? |
Thanks Junior Hacker for catching the missing period.
|
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. Cheers, Tink |
Hmmm
Good to know. |
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. Ah, the glory of Linux. Thanks again! |
Quote:
|
All times are GMT -5. The time now is 01:51 PM. |