Centos 查找命令之谜
Centos find command enigma
我的目录结构如下(Centos 7 和 Mac 都是同样的问题)
mkdir -p test/lemon-ip-ip/2020-04-08
mkdir -p test/king-ip-ip/2020-04-08
现在我只需要使用查找命令找到 "test/lemon-ip-ip/2020-04-08",我这样做了
find test/lemon-ip-ip -maxdepth 1 -name ????-??-??
这给出了正确答案
test/lemon-ip-ip/2020-04-08
这就是我想要的,并且到目前为止工作得很好。但是,当我创建目录时 "king-ip-ip/" 这个命令
find test/king-ip-ip -maxdepth 1 -name ????-??-??
给出了错误的输出
test/king-ip-ip/
test/king-ip-ip/2020-04-08
这也是直接返回父对象 "test/king-ip-ip/" 当我更改目录再次说 "test/king-ip/" 时,这种情况只发生在这个特定的字符串上,这很好用。我无法更改目录名称。谁能告诉我是什么导致了这个问题?
我需要最终输出为
test/king-ip-ip/2020-04-08
谢谢,
拉吉
原因是模式 ????-??-??
匹配任何 4、2 和 2 个字符,中间有破折号。此类字符串包括 2020-04-08
、aaaa-bb-cc
和 king-ip-ip
.
虽然您没有寻求替代方案,但我的建议是其中之一,具体取决于您使用它的详细信息:
# Don't use find at all
echo test/king-ip-ip/????-??-??
# Only search files strictly inside the directory, not the dir itself
find test/king-ip-ip/* -maxdepth 0 -name '????-??-??'
find test/king-ip-ip -maxdepth 1 -depth 1 -name '????-??-??'
# Only match numbers, not other characters
find test/king-ip-ip -maxdepth 1 -name '[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]'
我的目录结构如下(Centos 7 和 Mac 都是同样的问题)
mkdir -p test/lemon-ip-ip/2020-04-08
mkdir -p test/king-ip-ip/2020-04-08
现在我只需要使用查找命令找到 "test/lemon-ip-ip/2020-04-08",我这样做了
find test/lemon-ip-ip -maxdepth 1 -name ????-??-??
这给出了正确答案
test/lemon-ip-ip/2020-04-08
这就是我想要的,并且到目前为止工作得很好。但是,当我创建目录时 "king-ip-ip/" 这个命令
find test/king-ip-ip -maxdepth 1 -name ????-??-??
给出了错误的输出
test/king-ip-ip/
test/king-ip-ip/2020-04-08
这也是直接返回父对象 "test/king-ip-ip/" 当我更改目录再次说 "test/king-ip/" 时,这种情况只发生在这个特定的字符串上,这很好用。我无法更改目录名称。谁能告诉我是什么导致了这个问题?
我需要最终输出为
test/king-ip-ip/2020-04-08
谢谢, 拉吉
原因是模式 ????-??-??
匹配任何 4、2 和 2 个字符,中间有破折号。此类字符串包括 2020-04-08
、aaaa-bb-cc
和 king-ip-ip
.
虽然您没有寻求替代方案,但我的建议是其中之一,具体取决于您使用它的详细信息:
# Don't use find at all
echo test/king-ip-ip/????-??-??
# Only search files strictly inside the directory, not the dir itself
find test/king-ip-ip/* -maxdepth 0 -name '????-??-??'
find test/king-ip-ip -maxdepth 1 -depth 1 -name '????-??-??'
# Only match numbers, not other characters
find test/king-ip-ip -maxdepth 1 -name '[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]'