【问题标题】:excluding a directory from find and sed rename从 find 和 sed 重命名中排除目录
【发布时间】:2013-08-05 11:15:33
【问题描述】:

我正在使用此命令遍历所有文件、目录和子目录,以将任何提及 oldurl.com 的内容更改为 newurl.org

find . -type f -name '*.php' -exec sed -i 's|oldurl.com|newurl.org|g' {} +

它工作正常,但是,我需要从任何更改中排除三个子目录:/cache/archive/etc,因为在这些路径中使用上述命令更改 url 会破坏其他脚本。

没有太多的运气找到答案...有可能吗?

非常感谢您的任何建议/帮助。

【问题讨论】:

标签: linux bash replace sed find


【解决方案1】:

使用查找-not 选项:

find . -type f -name '*.php' -not \( -path './etc/*' -o -path './cache/*' -o -path './archive/*'  \) -exec sed -i 's|oldurl.com|newurl.org|g' {} \;

【讨论】:

    猜你喜欢
    • 2018-02-02
    • 2023-04-02
    • 2011-05-11
    • 1970-01-01
    • 2011-05-04
    • 2021-10-01
    • 1970-01-01
    • 2011-06-15
    相关资源
    最近更新 更多