【问题标题】:Finding a File and taking backup in the same directory在同一目录中查找文件并进行备份
【发布时间】:2017-04-24 04:23:25
【问题描述】:

假设我有一个文件夹/tmp,而你有一些文件abc.shkbc.shcdg.shnope.pykim.ruio.csv。现在,如果您要从不同的服务器(如 prod)复制新版本的 abc.shkbc.sh,但您希望将现有文件备份到同一文件夹中,如 abc.sh-12-08-2016kbc.sh-12-08-2016cdg.sh-12-08-2016,如何您可以在一个命令中执行此操作。所以这里是答案

find * -type f -exec cp {} {}_`date + "%m-%d-%Y"` \;

以上命令将备份该文件夹中的所有文件。

如果您只想备份 .sh 文件

find * -type f -name "*.sh" -exec cp {} {}_`date + "%m-%d-%Y"` \;

希望对你有帮助

【问题讨论】:

    标签: linux bash shell copy backup


    【解决方案1】:
    find * -type f -exec cp {} {}_date + "%m-%d-%Y" \; 
    

    以上命令将备份该文件夹中的所有文件。

    如果您只想备份 .sh 文件

    find * -type f -name "*.sh" -exec cp {} {}_date + "%m-%d-%Y" \;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-01-16
      • 2016-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-31
      • 1970-01-01
      相关资源
      最近更新 更多