samedi 17 janvier 2015

Why is the “move” word necessary when using find + xargs + rsync in a subshell [duplicate]



This question already has an answer here:




I often use this sort of command on my Mac to transfer files remotely:



find . -iname '*.txt' -print0 | xargs -0 -J % rsync -aP % user@ip:/foo/bar


I had to perform this on Linux. Since GNU versions of xargs don’t include the -J feature (-I flag and find -exec produce one rsync command per find result, which is not my intention), I solved it on Ubuntu using:



find . -iname '*.txt' -print0 | xargs -0 bash -c 'rsync -aP "$@" user@ip:/foo/bar' move


Questions:



  • Considering a folder with files a.txt, b.txt and c.txt, executing the command in it without appending the word “move” will disconsider c.txt. Why does that happen?

  • Are there any other suggestions to execute rsync only once, using all arguments originated from find? I tried using rsync's --files-from=- parameter to read from stdout, without much luck.


EDIT: Sorry for the duplicate. In the post suggested, I can see that "$@" expands args from 1 onwards, that's why $0 was disconsidered. A possible workaround for me was replacing $@ with ${@:0}. Even so, I still haven't found an answer to the necessity of moveat the end while using $@ as shown here (actually, any given character or word works! I fail to understand that).



Aucun commentaire:

Enregistrer un commentaire