gpt4 book ai didi

regex - 检查文件是否存在于 regex Linux 指定的目录中

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:22:34 28 4
gpt4 key购买 nike

我正在尝试在文件操作符中使用正则表达式来寻找一个文件,其中一个子目录是用正则表达式指定的,但我想知道这是否可能。我想我尝试了所有可能的引号和括号组合。是我遗漏了什么,还是文件运算符(operator)需要特定路径?

我不是很确定。有人可以澄清一下吗?

我想要实现的是这样的(这显然行不通,因为它将正则表达式部分作为子目录的名称)

if [[ -r '/agent/[0-9 .]*/bin/run.sh' ]]

最佳答案

find 有一个 -regex 选项

-regex pattern

File name matches regular expression pattern. This is a match on the whole path, not a search. For example, to match a file named ./fubar3', you can use the regular expression.*bar.' or .*b.*3, but not f.*r3. The regular expressions understood by find are by default Emacs Regular Expressions, but this can be changed with the -regextype option.

if find . -regex '/agent/[0-9 \.]*/bin/run.sh'

关于regex - 检查文件是否存在于 regex Linux 指定的目录中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37967164/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com