[英]linux: find common files from two directories with single command
目录 1: [anyName]-test/target/surefire-reports/*.xml
目录 2: target/surefire-reports/*.xml
jenkins shell cmd 我来了:
sh "jar -cMvf Test.zip target/surefire-reports/*.xml *-test/target/surefire-reports/*.xml "
只有一个目录存在(dir1 或 dir2),因此 shell 步骤总是因为没有文件或目录而失败。
在单个命令中查找 xml 文件没有失败的更好主意吗? (可能是一些正则表达式)谢谢!
尝试:
cd <TOP DIRECTORY>
find . -type f -name "*unitTest.xml" -print | xargs jar -cMvf Test.zip
我放了“*unitTest.xml,因为在 Dir2 中, J
是大写的。这样它只会捕获 JUnitTtest.xml 文件,如果它们存在的话。
所以find
命令的结果作为 arguments 到jar
命令。 这是由xargs
完成的。 find
不关心文件是否存在,所以没有错误。
在 bash 上测试。
使用 GNU find
:
find . -type f -regex '\./\([^/]*-test/\)?target/surefire-reports/[^/]*\.xml'\
-exec jar -cMvf Test.zip {} +
-regex
操作与常规 ( type -f
) 文件的路径相匹配。 这只会从 surefire surefire-reports
目录中添加*.xml
文件,而不是从其子目录中添加。 如果要包含子目录,请将[^/]*\.xml
为.*\.xml
。
使用 glob 模式的替代方法:
find target/surefire-reports *-test/target/surefire-reports -maxdepth 1 -type f\
-name '*.xml' -exec jar -cMvf Test.zip {} +
如果要包含子目录,请删除-maxdepth 1
。
从target
的父目录(您的项目目录)运行这两个命令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.