【问题标题】:Copy specific files from one folder to another in Unix/Linux在 Unix/Linux 中将特定文件从一个文件夹复制到另一个文件夹
【发布时间】:2019-06-23 18:00:55
【问题描述】:

我想做与here 非常相似的事情。不同之处在于我只想复制名称中包含特定字符串的文件(例如 file_00)。

使用this post 的答案,我尝试了这个:

cp -a /home/folder_1/. find . -name "*file_00*" - print /home/folder_2

但函数 cp 无法识别函数 find。然后我尝试了

cp -a /home/yanncochet/folder_1/. -e'file_00' /home/yanncochet/folder_2

但是同样的错误信息。有人可以帮忙吗?

【问题讨论】:

    标签: linux file copy


    【解决方案1】:

    find 是一个独立于cp 的程序。我认为你试图做的是使用 find 作为 cp 的输入。您可以为此使用command substitution

    cp $(find directory/ -name "*file_00*") destination/
    

    $(...) 基本上是在里面运行命令并返回它的输出。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-22
      • 2014-02-10
      • 2020-07-30
      • 2017-02-11
      • 1970-01-01
      • 2023-01-14
      相关资源
      最近更新 更多