LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 04-22-2007, 12:46 PM   #1
RevenantSeraph
Member
 
Registered: Jan 2007
Distribution: Ubuntu
Posts: 66

Rep: Reputation: 15
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?
 
Old 04-22-2007, 12:50 PM   #2
rocket357
Member
 
Registered: Mar 2007
Location: 127.0.0.1
Distribution: OpenBSD-CURRENT
Posts: 485
Blog Entries: 187

Rep: Reputation: 74
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
 
Old 04-22-2007, 12:50 PM   #3
Panagiotis_IOA
Member
 
Registered: Jan 2006
Location: Hellas, Europe
Distribution: Slackware 12
Posts: 238

Rep: Reputation: 32
If you are in the directory then type:

Code:
rm -R *
or from anywhere

Code:
rm -R /this/is/my/directory/*
These commands will remove any folder and file from your directory.

EDIT: Sorry, I don't think my reply is what you need. I misunderstood what you were asking for.

Last edited by Panagiotis_IOA; 04-22-2007 at 12:56 PM.
 
Old 04-22-2007, 03:02 PM   #4
cseanburns
Member
 
Registered: Nov 2003
Distribution: Fedora, Debian, Ubuntu, FreeBSD
Posts: 129

Rep: Reputation: 23
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
 
Old 04-23-2007, 01:58 AM   #5
Junior Hacker
Senior Member
 
Registered: Jan 2005
Location: North America
Distribution: Debian testing Mandriva Ubuntu
Posts: 2,687

Rep: Reputation: 61
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.
 
Old 04-23-2007, 05:19 PM   #6
cseanburns
Member
 
Registered: Nov 2003
Distribution: Fedora, Debian, Ubuntu, FreeBSD
Posts: 129

Rep: Reputation: 23
Thanks Junior Hacker for catching the missing period.
 
Old 04-24-2007, 07:50 PM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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
 
Old 04-24-2007, 08:54 PM   #8
Junior Hacker
Senior Member
 
Registered: Jan 2005
Location: North America
Distribution: Debian testing Mandriva Ubuntu
Posts: 2,687

Rep: Reputation: 61
Hmmm
Good to know.
 
Old 05-05-2007, 04:03 AM   #9
RevenantSeraph
Member
 
Registered: Jan 2007
Distribution: Ubuntu
Posts: 66

Original Poster
Rep: Reputation: 15
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!
 
Old 05-05-2007, 04:03 AM   #10
RevenantSeraph
Member
 
Registered: Jan 2007
Distribution: Ubuntu
Posts: 66

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Tinkster
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
And this is correct.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] FTP: recursive chmod (separate for directories and files) mgmax Linux - Software 11 01-29-2011 08:06 AM
How to do recursive file delete using specifier (*.tmp) from nested directories? Arodef Linux - General 3 11-11-2009 07:49 AM
Recursive directories listing cdog Linux - General 11 12-09-2006 07:04 AM
Recursive chmod with different values for files and directories? Z038 Linux - Newbie 2 06-07-2006 08:38 AM
call recursive find except on ./foo/ Hano Linux - General 1 07-30-2002 01:08 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:18 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