gpt4 book ai didi

linux - 如何在特定目录名称中查找文件?

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

所以我需要找到/home/中文件名为“options.php”的所有文件。

find . -name "options.php"

当“在家”时,它会找到所有 options.php 文件,但是,我只想找到位于/public_html/中的所有 options.php 文件。所以换句话说,它应该忽略找到的所有其他“options.php”文件。例如,积极/显示结果:

/home/usr1/public_html/options.php
/home/usr2/public_html/options.php

例如,不应该显示给我:

/home/usr1/public_html/wp-admin/options.php
/home/usr2/public_html/wp-content/plugins/whatever/options.php

最佳答案

您可以通过 -path 选项传递模式,如下所示:

find /home/ -path '*/public_html/options.php'

要获得更灵活的模式,请使用 -regex,它接受应用于整个路径的正则表达式。但在这种特殊情况下,-regex-path 相比没有任何优势:

find /home/ -regex '.*/public_html/options.php'

关于linux - 如何在特定目录名称中查找文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44561155/

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