如何使用两个查找单个xargs的结果

时间:2016-02-15 19:50:00

标签: linux shell

我在Ubuntu 14.04上。假设文件夹中存在未知数量的可执行文件。

ATest, BTest, CTest

我想使用与其名称相关的自定义命令行参数执行每个可执行文件。例如,

valgrind --xml=yes --xml-file=ATest.log ./ATest 
valgrind --xml=yes --xml-file=BTest.log ./BTest 
valgrind --xml=yes --xml-file=CTest.log ./CTest 

我可以通过

获取可执行文件
find . -executable -type f

我可以通过

获取自定义命令行参数
find . -executable -type f -printf '%f\n'

我能做到

find . -executable -type f | xargs -n 1 valgrind --xml=yes --xml-file=Test.log 

但遗憾的是,日志文件的名称未自定义。我试图将它合并如下,但它没有工作

find . -executable -type f -printf '%f\n' && find . -executable -type f | xargs -n 2 valgrind --xml=yes --xml-file={}.log

将两个find的结果组合成一个xargs的正确方法是什么?

2 个答案:

答案 0 :(得分:1)

您可以使用:

find . -executable -type f -printf '%f\n' |
xargs -I {} valgrind --xml=yes --xml-file={}.log ./{}

xargs

find . -name '*Test' -executable -type f -print0 |
xargs -0 -I {} bash -c 'valgrind --xml=yes --xml-file="${1##*/}.log" "$1"' - {}

这将执行以下3个命令:

valgrind --xml=yes --xml-file=ATest.log ./ATest
valgrind --xml=yes --xml-file=BTest.log ./BTest
valgrind --xml=yes --xml-file=CTest.log ./CTest

答案 1 :(得分:0)

使用255的-I开关:

xargs