關於xargs cp中,如何確定拷貝的源和目的 (copied)


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM