2011年6月28日 星期二

xargs - work with cp - specify the argument sequence

用 xargs 可以用來把前一個 command 的輸出轉到另一個 command 的 argument。
但是還有一些細節,例如 作為下一個 command 的第一還是第二個 argument ?

可以用 -I option 來作。

-I option 好像是用來賦予 xargs 傳遞的變數.
以 "把 RefBase.cpp copy 到 test" 為例
$ find . -name RefBase.cpp | xargs -I src cp src ~/test
期中的 -I src 就指定 find. 的結果用 'src'來代表。
所以 cp src ~/test 中的 src,就會被 find 的結果待換掉。




ref : http://www.cyberciti.biz/faq/linux-unix-bsd-xargs-construct-argument-lists-utility/