Results 1 to 9 of 9

Thread: how do I delete everything that's not an mp3?

  1. #1
    Join Date
    Jan 2007
    Location
    the states, oregon
    Beans
    94
    Distro
    Ubuntu 11.04 Natty Narwhal

    how do I delete everything that's not an mp3?

    I got a nice discography collection, but i want to strip out all the jpg's and m3u's and such. don't know what all's in there , and don't want to look. I want to run a recursive rm (or something) that'll delete all files (not folders) that don't end in ".mp3" anywhere in the discography's little sub-folder tree.

    Is there an easy way? Many thanks in advance.
    Jesus saves. Everyone else takes 10d6.

  2. #2
    Join Date
    May 2007
    Location
    On board my boat
    Beans
    483
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: how do I delete everything that's not an mp3?

    Goto the folder with the programs you want to delete
    Select LIST VIEW on the upper right
    sort by type
    select the files you don't want and send them to the trash
    (or select all the MP3s and move them)
    Don
    Looks fine to me but then I don't know/care what you run

  3. #3
    Join Date
    Jun 2008
    Location
    California
    Beans
    2,271
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: how do I delete everything that's not an mp3?

    The following will do what you want:

    Code:
    find /target/directory ! -iname '*.mp3' -type f -exec /bin/rm -f '{}' \;
    I would be hesitant to use this command because it deletes every file in the target directory and subdirectories that is not an MP3 file. One mistake and your computer doesn't work. If you do decide to use this command, I would recommend that you first run the following command, which echoes the files that will be deleted to the terminal window. Then, if all appears well, you can remove the echo command to actually delete the files.

    Code:
    find /target/directory ! -iname '*.mp3' -type f -exec echo /bin/rm -f '{}' \;
    Last edited by kaibob; May 6th, 2009 at 05:02 AM.

  4. #4
    Join Date
    Jan 2007
    Location
    the states, oregon
    Beans
    94
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: how do I delete everything that's not an mp3?

    Excellent! Many thanks! I'll be careful.
    Last edited by querent; May 6th, 2009 at 05:00 AM. Reason: missed previous post
    Jesus saves. Everyone else takes 10d6.

  5. #5
    Join Date
    Jun 2008
    Location
    California
    Beans
    2,271
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: how do I delete everything that's not an mp3?

    Quote Originally Posted by querent View Post
    Excellent! Many thanks! I'll be careful.
    Please note that I changed -name to -iname in the command. This makes the search case insensitive and retains both file.mp3 and file.MP3.

  6. #6
    Join Date
    Jan 2007
    Location
    the states, oregon
    Beans
    94
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: how do I delete everything that's not an mp3?

    Right. I'm in the man pages now trying to figure out what I'll be doing.

    Thanks for the lead.
    Jesus saves. Everyone else takes 10d6.

  7. #7
    Join Date
    Oct 2007
    Beans
    1,832

    Re: how do I delete everything that's not an mp3?

    for a safer, less technical route, copy everything that's mp3 into another directory, rm everything that's left, and move your mp3's out.

    Though, looking briefly, the exec command above will work.

  8. #8
    Join Date
    Jan 2007
    Location
    the states, oregon
    Beans
    94
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: how do I delete everything that's not an mp3?

    And it worked! Many thanks again.

    Took me a while to get that the "!" in there was what was keeping it from deleting only my mp3's.

    Problems are where you learn. Thanks, friend!
    Jesus saves. Everyone else takes 10d6.

  9. #9
    Join Date
    Dec 2006
    Beans
    7,349

    Re: how do I delete everything that's not an mp3?

    Hi kaibob,

    Quote Originally Posted by kaibob View Post
    If you do decide to use this command, I would recommend that you first run the following command, which echoes the files that will be deleted to the terminal window. Then, if all appears well, you can remove the echo command to actually delete the files.

    Code:
    find /target/directory ! -iname '*.mp3' -type f -exec echo /bin/rm -f '{}' \;
    Always best to be cautious . A variation of the above could be:

    Code:
    find /directory ! -iname '*.mp3' -type f -ok rm {} \;
    Andrew
    You think that's air you're breathing now?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •