Active Topics

 


Reply
Thread Tools
Posts: 57 | Thanked: 9 times | Joined on Nov 2009 @ Glasgow, Scotland
#1
My mate gave me a lot of music the other day. But about half is DRMed and thus unplayable.

I need to know how to remove all of a certain file type from a folder and its sub folders.

I've only been using linux (maemo 5 and ubuntu 9.04/10.04) for a year or so, i thought using (as root):
Code:
rm -R *.m4p
would work, but it says cannot find file.

Ive managed to find all files with said extension by using(as root):
Code:
find | grep m4p
and it lists all references to all m4p files, but how do i give this output to the 'rm' command.

I've tried(also as root):
Code:
find | grep m4p | rm
rm | find | grep m4p
to no avail.

Its just my lack of knowledge on how the pipe system works

EDIT:
The directory is /home/user/MyDocs/.sounds/Music
there are sub directories per artist then album e.g.

/home/user/MyDocs/.sounds/Music/Andrew WK/Close Calls With Brick Walls/Track1.m4p


Any help appreciated.

Cheers.

Last edited by finlaybob; 2011-02-04 at 15:08.
 

The Following User Says Thank You to finlaybob For This Useful Post:
Posts: 2,102 | Thanked: 1,937 times | Joined on Sep 2008 @ Berlin, Germany
#2
My usage pattern for recursively removing would be
Code:
rm -rf *.m4p
 

The Following User Says Thank You to michaaa62 For This Useful Post:
Posts: 662 | Thanked: 653 times | Joined on Feb 2010
#3
Little command here:

sza=$(ls | grep m4p); rm $sza

should suffice.
 

The Following 2 Users Say Thank You to Reffyyyy For This Useful Post:
Posts: 57 | Thanked: 9 times | Joined on Nov 2009 @ Glasgow, Scotland
#4
Thanks to both michaaa62 & Reffyyyy for swift replies!

however running as root:

Code:
rm -rf *.m4p
doesnt seem to be deleting the files, however it doesnt give any output.

also:

Code:
sza=$(ls | grep m4p); rm $sza
Gives:

Code:
Usage rm [OPTION] ... [FILE] ...
Like when you give 'rm' an invalid parameter.
 
Posts: 3,617 | Thanked: 2,412 times | Joined on Nov 2009 @ Cambridge, UK
#5
Try one of the following:
Code:
rm `find . -name "*.mp4"`
find . -name "*.mp4" | xargs rm
find . -name "*.mp4" -delete
The last will probably only work if you have the GNU version of find installed, but the others should work with the standard busybox version.
 

The Following 2 Users Say Thank You to Rob1n For This Useful Post:
Copernicus's Avatar
Posts: 1,986 | Thanked: 7,698 times | Joined on Dec 2010 @ Dayton, Ohio
#6
You should be able to use the backtick operator to pass the output of find to rm, as so:

Code:
rm `find | grep m4p`
I think the -R option of rm only applies to directories, so I doubt that would be of any use here.

Actually, I'm kind of surprised that that find command works for you; I thought you'd at least have to specify the path to look for files. I usually give find a command something like this:

Code:
find . -name "*.m4p"
Which asks find to look in the current directory (".") for files with the extension m4p. find will recurse through any subdirectories by default, but I don't know if it will enter hidden directories; you might have to run the command something like:

Code:
find .sounds/Music -name "*.m4p"
So, in total, I'd probably have:

Code:
rm `find .sounds/Music -name "*.m4p"`
Check the output of the find command first, though, to be certain what you'd be deleting...
 

The Following User Says Thank You to Copernicus For This Useful Post:
Posts: 662 | Thanked: 653 times | Joined on Feb 2010
#7
Were you in the folder when you ran the command?

If not:

sza=$(ls -R | grep m4p); rm $sza

to delete them all recursively. Works every time for me.

EDIT: I spoke too soon. It appears that ls won't display the full path when recursive is switched on.

Last edited by Reffyyyy; 2011-02-04 at 15:44.
 

The Following User Says Thank You to Reffyyyy For This Useful Post:
Posts: 662 | Thanked: 653 times | Joined on Feb 2010
#8
I like this one more:

sz+$(find . -name \*.m4p); rm $sz

Tested this one a few times. If it doesn't work, you can have my shoes.

Forgive my failures, I had no sleep last night.

Last edited by Reffyyyy; 2011-02-04 at 15:58.
 

The Following User Says Thank You to Reffyyyy For This Useful Post:
inkirby's Avatar
Posts: 55 | Thanked: 16 times | Joined on Jun 2010 @ Thailand
#9
Thanks to the thread, this can help me in Mac too.
 

The Following User Says Thank You to inkirby For This Useful Post:
Posts: 57 | Thanked: 9 times | Joined on Nov 2009 @ Glasgow, Scotland
#10
Thanks for all replies, however nothing is working

All commands do something similar to this

I'm now at home so using SSH instead of tiny little keys .

using a single file at the moment, this is the path:
Code:
./Neneh Cherry, Speech & Speech & Neneh Cherry/1 Giant Leap/Braided Hair.m4p
this is the command:

Code:
Nokia-N900:/home/user/MyDocs/.sounds/Music# sz=$(find | grep Braided); rm $sz
This is the output

Code:
rm: cannot remove './Neneh': No such file or directory
rm: cannot remove 'Cherry,': No such file or directory
rm: cannot remove 'Speech': No such file or directory
rm: cannot remove '&': No such file or directory
rm: cannot remove 'Speech': No such file or directory
rm: cannot remove '&': No such file or directory
rm: cannot remove 'Neneh': No such file or directory
rm: cannot remove 'Cherry/1': No such file or directory
rm: cannot remove 'Giant': No such file or directory
rm: cannot remove 'Leap/Braided': No such file or directory
rm: cannot remove 'Hair.m4p': No such file or directory
Nokia-N900:/home/user/MyDocs/.sounds/Music#
 
Reply


 
Forum Jump


All times are GMT. The time now is 19:40.