Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

  cat hosts | xargs -I{} ssh root@{} hostname
glad to know this one :-)

  echo y | xargs -Ix echo x
how tricky!


I agree, this is one of my favorite tricks. I like to think of xargs as a `map` function over stdin lines.

As the article mentions, especially useful when combined with the -P flag for paralellism.

    cat urlpaths.txt | xargs -I{} -P wget domain.com/{}
Another handy trick, is to use `sh -c` or `bash -c` to include multiple commands with xargs.

    cat dirs.txt | xargs -I{} sh -c 'cd {}; touch file;'




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: