如何使用 find 命令忽略文件
我正在尝试使用命令
名称找到伪影:获取通往Java Artifact的路径
运行:echo java_artifact = $(findbuild/libs/*。jar -type f)> $ gt; $ github_env
:
- Echo Java_artifact = $(findbuild /
- ) libs/abc-plain.jar
我只想选择abc.jar文件。
谁能建议我如何实现这一目标?
I'm trying to find artifact using the command
name: Get path to Java artifact
run:echo JAVA_ARTIFACT=$(findbuild/libs/*.jar -type f) >>$GITHUB_ENV
The problem is I have 2 artifacts in that directory
- build/libs/abc.jar
- build/libs/abc-plain.jar
I want to pick only abc.jar file.
Can anyone suggest how can I achieve this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
find
命令可以与正则表达式一起使用,这样可以轻松获得任何类型的复杂搜索结果。工作原理:find
命令与-regex
一起使用,而不是-name
。find
如何将文件名传递给正则表达式?假设我们有以下目录结构:
并且我们坐在
someone
中,如果我们在没有任何进一步参数的情况下执行
find .
,我们会得到:因此,我们可以使用正则表达式搜索:
.
-
字符.jar< 结尾 /code>
这会导致:
一起:
find . -regex '.*/[^-]+.jar'
或者如果您只想在
build/libs/
中搜索find ./build/libs -regex '. */[^-]+.jar'
您可以在那里找到在线正则表达式工具。
The
find
command can be used with regular expressions which makes it easy to get any kind of complex search results. How it works:find
command with-regex
instead of-name
.How
find
passes the filename to the regular expression?Assume we have the following directory structure:
and we are sitting in
someone
if we execute
find .
without any further arguments, we get:So we can for example search with regex for:
.
-
character in any number of character.jar
This results in:
And all together:
find . -regex '.*/[^-]+.jar'
or if you ONLY want to search in
build/libs/
find ./build/libs -regex '.*/[^-]+.jar'
You find a online regex tool there.
查找命令支持标准UNIX等级匹配,包括或排除文件。您可以轻松地使用Regex编写复杂的查询,同时查找命令将每个/file/to/to/path的目录树递归下降,以评估表达式。
The find command support standard UNIX regex to match, include or exclude files. You can write complex queries easily with regex while finding the command recursively descends the directory tree for each /file/to/path listed, evaluating an expression.
由于您尚未清楚地提到您不希望文件名中的连字符
-
,因此我假设在没有> -
的情况下找到文件。我会尝试这样的事情。匹配下案例,上案例,数值&amp;
.jar
带有REGEX
的扩展。查找build/libs/-regextype posix-egrep -regex'。*/[a-za-z0-9]+\。jar'
我在本地测试时的输出低于输出。
您可以尝试以上命令在这里
Since you haven't clearly mentioned that you don't want the hyphen
-
in the filename, I'm assuming to find files without-
.I would try something like this. Matching lower-case, upper-case, numerical &
.jar
extension withregex
.find build/libs/ -regextype posix-egrep -regex '.*/[a-zA-Z0-9]+\.jar'
I got below output when tested locally.
You can try above commands here