0

as I am very new to rsync, I came across this code somewhere in the server and decided to try it out. It was a dry-run but there are a few parts within this line that I do not understand.

Do correct me if my interpretation below are wrong :x

find -name "*.jpg" | xargs -I icon sudo rsync -azuvhE -n icon tango:/jobs/prime/Item/icon

Firstly, I understand the first part of find -name "*.jpg" and it is looking for any .jpg files within the directory stated.

But I do not understand the meaning of | and xargs -I icon.. For the latter part, I presume it is like defining icon as a variable?

Then as for the last part, as I am crossing referencing between 2 servers (alphis which I am currently on) and tango, I presume it is referencing against the tango/jobs/prime/Item/icon?

dissidia
  • 1,531
  • 3
  • 23
  • 53

1 Answers1

2
   find -name "*.jpg" | \     # find jpeg files (assume no white space)
          xargs -I icon \     # get file names from find, call them icon
          sudo rsync -azuvhE -n icon # copy each file to ....
          tango:/jobs/prime/Item/icon # this folder on tango

This should be an equivalent command:

sudo find -name "*.jpg" -exec rsync -azuvhE -n {} tango:/jobs/prime/Item/ \;
perreal
  • 94,503
  • 21
  • 155
  • 181
  • Btw I am curious, since I am on the server alphis, do I need to do another cross file referencing from tango to alphis? Currently my terminal is displayed as `tnt@alphis find -name "*.jpg" | xargs -I icon sudo rsync -azuvhE -n icon tango:/jobs/prime/Item/icon` and so, do I need to change my ssh so that it will be: `tnt@tango find -name "*.jpg" | xargs -I icon sudo rsync -azuvhE -n icon alphis:/jobs/prime/Item/icon`? – dissidia Apr 04 '14 at 04:44
  • @user3212246, xargs is necessary because you want to get the names from stdin and read it as arguments with rsync. I added another method that does not use xargs. – perreal Apr 04 '14 at 04:57
  • @user3212246, you don't want to be on tango if you want to copy files you find on alphis. – perreal Apr 04 '14 at 04:58
  • Can I take it that running the command once will add/ check the file differences from both sides? (Pardon me my breakdown wording) If it is true, then I can say that if I am in server Alphis, then the code line behind will be directed to server Tango:..., or, likewise if I am in server Tango, I will just change it to Alphis:...? – dissidia Apr 04 '14 at 07:43
  • it will only update the remote directory. see: http://www.linuxmanpages.com/man1/rsync.1.php. The command updates existing files on the remote system if the local system has updated versions. – perreal Apr 04 '14 at 08:05
  • Correct me if I am wrong, but upon reading the link you have given me, can I say that rsync is a one-way street? – dissidia Apr 04 '14 at 08:42
  • That's right, you can run it twice though: http://stackoverflow.com/q/1602324/390913 – perreal Apr 04 '14 at 09:18
  • I see. I keep having the misinterpretation in my code that it can run both ways as it checks and update on the file differences... Well, I guess this would means I would need to run it again. Thanks! – dissidia Apr 04 '14 at 09:33