【问题标题】:How to write svn shell script in centos [closed]如何在centos中编写svn shell脚本[关闭]
【发布时间】:2020-10-29 06:02:36
【问题描述】:

我在 CentOS 中有一个网站,它使用 SVN 来更新和提交。

我想通过 crontab 编写一个 shell 脚本来自动运行调度工作。

我已经测试了一个 SVN 命令,svn status | grep ^?
它显示如下结果:

M index.php<br/>
M data/config.php<br/>
? date/aaa.php<br/>
? images/bbb.php<br/>
? images/product1.jpg<br/>
? images/product2.jpg<br/>
? themes/ccc.php<br/>
? themes/index.html<br/>
? temp/compiled/index.php<br/>
? temp/compiled/article.php<br/>
? temp/compiled/footer.php<br/>

我写了一个SVN命令,可以删除所有的unversion和修改php文件,如下:

svn 状态 --no-ignore | grep ".php$" | sed's/^? //' | xargs rm -rf

我想写一个可以帮助我的shell脚本:

  • 删除unversion文件,修改文件除外
  • 只删除php文件
  • 临时文件夹中的文件除外

请帮帮我,谢谢大家

【问题讨论】:

    标签: svn centos sh


    【解决方案1】:

    使用 grep 和选项 -v 排除 temp 下的文件路径。为了使命令更安全,我还将在rm 命令中跳过-r-f

    svn status --no-ignore | grep '^?.*\.php$' | grep -v '^? *temp/' | sed 's/^? *//' | xargs rm
    

    【讨论】:

    • 记住grep 'x' | sed 's/y/z/'可以重构为sed -n '/x/s/y/z/p'。您还可以通过类似的重构轻松摆脱最后一个grep。另见useless use of grep.
    • @tripleee 除了简洁和高效之外,我们还需要考虑非 sed 专家(比如我)的可读性。另一个可读的替代方法是使用 awk。
    • 我有一台windows系统的电脑。如何在 windows bat 中做同样的工作?
    • 我读过sed,但我不知道要写这个命令。
    猜你喜欢
    • 1970-01-01
    • 2014-02-11
    • 2011-06-24
    • 2013-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多