加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

bash – 如何将结果传递给CP,使带有空格的文件名有效

发布时间:2020-12-15 22:19:06 所属栏目:安全 来源:网络整理
导读:参见英文答案 How to pass command output as multiple arguments to another command????????????????????????????????????4个 我正在尝试将具有特定附件的文件复制到其他目录,并保留其相对路径.从我调用的原始顶部路径: cp --parents `find . -name *.pd
参见英文答案 > How to pass command output as multiple arguments to another command????????????????????????????????????4个
我正在尝试将具有特定附件的文件复制到其他目录,并保留其相对路径.从我调用的原始顶部路径:

cp --parents `find . -name *.pdf -print` /new_path/

我相信这有效;但是,只有找到的文件名称中没有空格.

我也尝试过:

cp --parents `find . -name *.pdf -print0` /new_path/

这显然不起作用,因为没有新行字符cp收到错误的名称.

是否可以用引号包围查找结果?

解决方法

试试这个:

find . -name *.pdf -print0 | xargs -0 -n 1 -Ifoo cp --parents foo /new_path/

要么

find . -name *.pdf -exec cp --parents {} /new_path/ ;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读