Feed on
Posts
Comments

say you’ve got a stream of filenames that you’d like to remove.  for instance, i’ve got a bunch of filenames that pop out of this command:

grep -v “,” `search “boot0.txt”` | sed ‘s/boot.*//’

turns out i can’t directly pipe this to rm.  instead, i’ve got to use the xargs command, as so:

grep -v “,” `search “boot0.txt”` | sed ‘s/boot.*//’ | xargs rm -r


Bookmark and Share

if that was helpful ...

check out the other tips and tricks i've compiled on these pages. you might learn something else interesting!

11 Responses to “pipe filenames to rm in unix”

  1. on 04 Mar 2009 at 3:54 pm Anton Thorn

    Priceless! Thank you! :)

  2. on 21 Jun 2009 at 11:37 am Donald Kail

    Awesome!

  3. on 16 Sep 2009 at 5:28 pm danips

    Thanks it worked :)
    BTW nice blog header ^_^

  4. on 21 Nov 2009 at 10:59 am ikenna

    thanks mate!

  5. on 05 Feb 2010 at 10:37 pm Anonymous

    great command

  6. on 01 Feb 2011 at 4:15 pm Elia

    very nice menu!!!!

  7. on 23 Aug 2011 at 5:17 pm Me

    Worked great!!!

  8. on 02 Nov 2011 at 2:12 pm Åsmund Stavdahl

    Awesome tip and even more awesome header :D

  9. on 24 Aug 2012 at 5:03 am JFred

    so much time has passed with this awfull “while read line;do rm $line;done < <(ls things)"… *sigh*
    Many thanks !!

  10. on 15 Oct 2012 at 7:23 am RockFord

    have you ever tried vipe?

    ex.:
    git status -u | vipe | xargs -Rf

    ;-)

  11. on 06 Feb 2014 at 7:53 pm Doc

    Thanks man. xargs eh? Cool.

Did I get this wrong? Let me know!

Trackback URI | Comments RSS

More blogs about http://desk.stinkpot.org:8080/tricks.