maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Maemo 5 / Fremantle (https://talk.maemo.org/forumdisplay.php?f=40)
-   -   linux commands question (https://talk.maemo.org/showthread.php?t=69353)

finlaybob 2011-02-04 14:20

linux commands question
 
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.

michaaa62 2011-02-04 14:33

Re: linux commands question
 
My usage pattern for recursively removing would be
Code:

rm -rf *.m4p

Reffyyyy 2011-02-04 14:38

Re: linux commands question
 
Little command here:

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

should suffice.

finlaybob 2011-02-04 15:05

Re: linux commands question
 
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.

Rob1n 2011-02-04 15:20

Re: linux commands question
 
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.

Copernicus 2011-02-04 15:33

Re: linux commands question
 
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... :)

Reffyyyy 2011-02-04 15:38

Re: linux commands question
 
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.

Reffyyyy 2011-02-04 15:54

Re: linux commands question
 
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.

inkirby 2011-02-04 16:06

Re: linux commands question
 
Thanks to the thread, this can help me in Mac too.

finlaybob 2011-02-04 16:35

Re: linux commands question
 
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#



All times are GMT. The time now is 06:49.

vBulletin® Version 3.8.8