gpt4 book ai didi

linux - 查找具有可变字符数的文件名

转载 作者:太空宇宙 更新时间:2023-11-04 09:31:13 25 4
gpt4 key购买 nike

使用 Ubuntu。

我有一个目录,有一些子目录,其中可能有一些名称格式如下的文件:

core.foo.1234
core.bar.65432

因此,它们都以“核心”开头。然后是进程名称,然后是 PID 号,通常是 4 或 5 位数字。

我的基于 Python 的工具使用两个“查找”命令来查找它们,如下所示:

the_cmd4 = "find " + directory_name + " -name \"core\.*\.[0-9][0-9][0-9][0-9]\"";

the_cmd5 = "find " + directory_name + " -name \"core\.*\.[0-9][0-9][0-9][0-9][0-9]\"";

所以,这实际上是这样调用“查找”工具:

find . -name "core.*.[0-9][0-9][0-9][0-9]" 

必须有一种方法来指定具有可变数字字符数的“查找”——而不是分两步进行。

有吗?

提前致谢。

最佳答案

我认为你可以使用支持更强大 RE 的 grep 再次过滤:

find . -name "core*" | grep "core.*.[0-9]\+"

关于linux - 查找具有可变字符数的文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31112348/

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