find - 如何使用find在指定子目录中查找文件

标签 find

我有多个网站使用我自己的模板,现在我已经更新了我的模板,并且我想使用 find 来更新模板。

如果我这样做

find . -name template.css -print -exec cp NEW_FILE {} \;

然后所有其他 template.css 将被覆盖。

我只希望 template.css 位于目录 mytemplate/css 中时被覆盖。

有人有想法吗?

示例:

/site1/templates/mytemplate/css/template.css*
/site1/templates/othertemplate/css/template.css
/site1/templates/other2template/css/template.css
/site2/templates/mytemplate/css/template.css*
/site2/templates/othertemplate/css/template.css
/site2/templates/other2template/css/template.css
/site3/templates/mytemplate/css/template.css*
/site3/templates/othertemplate/css/template.css
/site3/templates/other2template/css/template.css

带 * 的文件只能被覆盖

最佳答案

您可以使用-wholename标志和正确的正则表达式。这应该适用于您的示例:

find . -wholename "*/mytemplate/css/template.css" -print -exec cp NEW_FILE {} \;

关于find - 如何使用find在指定子目录中查找文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34838449/

相关文章:

linux - 将整个目录结构的每个文件复制到另一个的基本路径中

linux - linux find中排除隐藏文件和文件夹

regex - 如何让正则表达式 'or groups' 像 (foo|bar) 与 find -regex 一起使用? (操作系统)

java - 从java搜索时Mongo Id被_id覆盖

linux - linux命令将子目录的文件分别向上一级移动

algorithm - 正负根的求根算法

Linux "find"返回所有文件

linux - 如何提取具有特定模式的子文件夹名称?

linux - 查找具有某些属性的文件

正则表达式,获取字符串第二次出现后的内容