Menu

Main Menu
Talk Get Daily Search

Member's Online

    User Name
    Password

    linux commands question

    Reply
    Page 1 of 2 | 1   2   | Next
    finlaybob | # 1 | 2011-02-04, 14:20 | Report

    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.

    Edit | Forward | Quote | Quick Reply | Thanks

    Last edited by finlaybob; 2011-02-04 at 15:08.
    The Following User Says Thank You to finlaybob For This Useful Post:
    inkirby

     
    michaaa62 | # 2 | 2011-02-04, 14:33 | Report

    My usage pattern for recursively removing would be
    Code:
    rm -rf *.m4p

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following User Says Thank You to michaaa62 For This Useful Post:
    finlaybob

     
    Reffyyyy | # 3 | 2011-02-04, 14:38 | Report

    Little command here:

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

    should suffice.

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following 2 Users Say Thank You to Reffyyyy For This Useful Post:
    finlaybob, Mentalist Traceur

     
    finlaybob | # 4 | 2011-02-04, 15:05 | Report

    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.

    Edit | Forward | Quote | Quick Reply | Thanks

     
    Rob1n | # 5 | 2011-02-04, 15:20 | Report

    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.

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following 2 Users Say Thank You to Rob1n For This Useful Post:
    finlaybob, stlpaul

     
    Copernicus | # 6 | 2011-02-04, 15:33 | Report

    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...

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following User Says Thank You to Copernicus For This Useful Post:
    finlaybob

     
    Reffyyyy | # 7 | 2011-02-04, 15:38 | Report

    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.

    Edit | Forward | Quote | Quick Reply | Thanks

    Last edited by Reffyyyy; 2011-02-04 at 15:44.
    The Following User Says Thank You to Reffyyyy For This Useful Post:
    finlaybob

     
    Reffyyyy | # 8 | 2011-02-04, 15:54 | Report

    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.

    Edit | Forward | Quote | Quick Reply | Thanks

    Last edited by Reffyyyy; 2011-02-04 at 15:58.
    The Following User Says Thank You to Reffyyyy For This Useful Post:
    finlaybob

     
    inkirby | # 9 | 2011-02-04, 16:06 | Report

    Thanks to the thread, this can help me in Mac too.

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following User Says Thank You to inkirby For This Useful Post:
    finlaybob

     
    finlaybob | # 10 | 2011-02-04, 16:35 | Report

    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#

    Edit | Forward | Quote | Quick Reply | Thanks

     
    Page 1 of 2 | 1   2   | Next
vBulletin® Version 3.8.8
Normal Logout