I have a Back-Up HDD (not TimeMachine) with only very important data backed-up there. Every once in a while, I connect the external hard disk and sync the files per hand. As the files I am syncing are always the same, it came to my mind that I could automate the whole process as a shell script.

However, I could not find a helpful command that compares A to B (which will then ask me to sync if sync is necessary). I have found rsync but the documentations did not explain how to synchronise a single directory.

I also haven't figured out how to change directory to an external HDD connected via USB.


This is easy to accomplish using rsync. The easiest route is to open terminal and type rsync -r and that drag the source folder to the window, followed by the destination folder. -r stands for recursive, so it will look inside the folder and its subfolders. I just synced a folder on my desktop and a mounted USB drive with this command:

rsync -r /Users/My-User/Desktop/Test_folder /Volumes/My-USB-Drive/Test_on_USB

It actually creates the Test_folder inside the Test_on_USB folder. I'm not an expert on all the options, but you can find them here: http://everythinglinux.org/rsync/

Let me know if that accomplishes what you're after.

  • Thank you. I've decided to go with another form of rsync suggested in another question on SuperUser because it fits my bash script better. – Narusan Jul 30 '17 at 18:18
  • Excellent. Out of curiosity: can you tell me why you would use diff first? As rsync can compare the folders for you and do all the syncing as well. – liteowl Jul 30 '17 at 22:16
  • Because it's cool to be able to state that everything is up-to-date, and this information might be useful. I won't run into a cpu or time problem by including this line, so I just left it in for the fun :P – Narusan Jul 30 '17 at 22:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .