Results 1 to 5 of 5

Thread: find (multiple extensions)... rm! not working now...

  1. #1
    Join Date
    Feb 2005
    Location
    Cleveland, OH
    Beans
    232
    Distro
    Ubuntu 14.04 Trusty Tahr

    find (multiple extensions)... rm! not working now...

    I have an entry in my crontab to delete superfluous files from my unwatched videos directory. Originally it was just used to remove "*.nfo" files, but now I have additional file extensions that I want to delete. The new entry is
    Code:
    find /home/shares/video/unwatched/ -iname "*.jpg" -o -iname "*.tbn" -o -iname "*.nfo-orig" -exec rm -rf {} \;
    I started out by surrounding the -iname parameters with parentheses like this \( ... \) but got errors, so I removed the parentheses. I've run the find part of the command from the shell, and it returns everything I want to delete, but the -exec rm is not deleting the files.

    I'm confused!

  2. #2
    Join Date
    Apr 2006
    Location
    Montana
    Beans
    Hidden!
    Distro
    Kubuntu Development Release

    Re: find (multiple extensions)... rm! not working now...

    You have to either use xargs or quote the {}

    xargs

    Code:
    find <your optios> -print0 | xargs -0 /bin/rm -f
    But that will fail if you have spaces in the file names.

    quote the {}

    Code:
    find /home/shares/video/unwatched/ -iname "*.jpg" -o -iname "*.tbn" -o -iname "*.nfo-orig" -exec rm -rf '{}' \;
    There are two mistakes one can make along the road to truth...not going all the way, and not starting.
    --Prince Gautama Siddharta

    #ubuntuforums web interface

  3. #3
    Join Date
    Feb 2005
    Location
    Cleveland, OH
    Beans
    232
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: find (multiple extensions)... rm! not working now...

    Quote Originally Posted by bodhi.zazen View Post
    You have to either use xargs or quote the {}

    xargs

    Code:
    find <your optios> -print0 | xargs -0 /bin/rm -f
    But that will fail if you have spaces in the file names.

    quote the {}

    Code:
    find /home/shares/video/unwatched/ -iname "*.jpg" -o -iname "*.tbn" -o -iname "*.nfo-orig" -exec rm -rf '{}' \;
    I tried adding the single quotes around the {}, but it still wasn't deleting the files. Strange!

  4. #4
    Join Date
    Apr 2006
    Location
    Montana
    Beans
    Hidden!
    Distro
    Kubuntu Development Release

    Re: find (multiple extensions)... rm! not working now...

    I see it is because you may only pass one set of results to a command, so write a script to loop through those one at a time.
    There are two mistakes one can make along the road to truth...not going all the way, and not starting.
    --Prince Gautama Siddharta

    #ubuntuforums web interface

  5. #5
    Join Date
    Feb 2007
    Location
    Romania
    Beans
    Hidden!

    Re: find (multiple extensions)... rm! not working now...

    Hmmm, your command will only delete the *.nfo-orig files.

    You probably want to delete the .jpg and .tbn files as well. Right?

    Code:
    find ./path \( -iname \*.jpg -o -iname \*.tbn -o -iname \*.nfo-orig \) -exec rm -i {} +
    In this context, {} has no special meaning, so you don't have to quote it.

    The -exec command {} + variant will run the command on a set of files instead of invoking the command for each file.

    GNU find also has a -delete option.

    ... -print0 | xargs -0 ... should also do the trick and it should work with any filename.

    For more info check out BashFAQ 075 (link in my signature).

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
  •