【问题标题】:How to grep and copy files with spaces in their names如何grep和复制名称中带有空格的文件
【发布时间】:2017-04-25 14:00:03
【问题描述】:

我有一些文件名中有空格。我想选择所有包含特定文本的文件,并将这些文件复制到另一个目录。我可以使用grep 来做第一部分,但是卡住了将文件名列表传递给cpcp 总是根据空格分割文件名。我试过xargs --null,但这对我没有好处。有什么实用的解决办法吗?

【问题讨论】:

    标签: shell grep xargs cp


    【解决方案1】:

    grepxargs 使用--null 选项:

    grep --null --files-with-matches 'word' * | xargs --null cp -t "$target_dir"
    

    --null 选项导致命令以零字节而不是换行符终止文件名。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-22
      • 2012-08-15
      • 2020-01-12
      • 1970-01-01
      • 2014-05-08
      • 1970-01-01
      • 2019-02-25
      • 2015-06-05
      相关资源
      最近更新 更多