关于xargs cp中,如何确定拷贝的源和目的 (copied)


来源:

http://bbs.chinaunix.net/thread-1022095-1-1.html


Seker:

find . -name "*" |xargs cp ????

这里 xargs cp 怎么区分cp源 和 cp目的
例如:想把 查询到的文件 都copy到/home/users/中去
        find . -name "*" | xargs cp /home/users/
cp命令在这里就变成:cp /home/users/ Find_file

默认从管道传来的值是放在最后的 这样的话原本想做cp源文件的值和目的目录的参数就颠倒了
有办法解决一下吗?
xargs 没有想-exec 那种 {} 的变量吗?



davistar:

find . -name "*" | xargs -i cp {}  /home/users/


nuclearxin:

-i 和{} 什么关系?


davistar:

-i 表示 find 传递给xargs的结果 由{}来代替



--------------------------------------------------------------

在Ubuntu (Ubuntu 12.04.4 LTS \n \l)上查到的结果:

       -I replace-str
              Replace occurrences of replace-str in the initial-arguments with names read from standard input.  Also, unquoted blanks do not terminate input items; instead the separator is  the  new‐
              line character.  Implies -x and -L 1.

       --replace[=replace-str]
       -i[replace-str]
              This option is a synonym for -Ireplace-str if replace-str is specified, and for -I{} otherwise.  This option is deprecated; use -I instead.



[user@host:pkg]$ find -type f | grep -v orig | grep -v tmp |xargs grep -l 'cp -rp' | xargs cp tmp2
cp: target `./mkpkg.sh' is not a directory
[user@host:pkg]$ cd tmp2
[user@host:tmp2]$ ls
[user@host:tmp2]$ cd ../
[user@host:pkg]$ find -type f | grep -v orig | grep -v tmp |xargs grep -l 'cp -rp' | xargs cp {} tmp2
cp: target `./mkpkg.sh' is not a directory
[user@host:pkg]$ find -type f | grep -v orig | grep -v tmp |xargs grep -l 'cp -rp' | xargs -i cp {} tmp2
[user@host:pkg]$ cd tmp2
[user@host:tmp2]$ ls
i




  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值