I have a local folder which I want to synchronize with a remote folder through SSH, and I'd like to do it through rsync. I would always call rsync with the same arguments, and same source and destination, when I want to sync this specific folder.

Is there a way to create a folder-specific configuration file for rsync, placed in this local folder, so that when I simply run rsync in this folder, it will automatically take the defaults from the configuration file and start synching? Something like how you'd simply call git status in a folder, and it reads the repo from there - no further arguments about the path to the repo given.

  • If you always use the same exact rsync command in that folder, couldn't you make a one-line shell script file in that folder for this? The only other method I can think of might be to use rsync as a daemon (here and here), but I'm unfamiliar with that process. – Ryan Apr 9 '16 at 11:35
  • you can have .rsync-filter files (see man rsync and search for both -F and FILTER RULES) but that doesn't allow you to specify options, only exclude and include and other filtering rules. – cas Apr 10 '16 at 0:14
  • @Ryan: a shell script containing rsync would have been my next option - I've already done that before. Just checking if there's a more elegant way. – CamilB Apr 10 '16 at 9:47
  • @cas: Thanks, didn't know about filter rules. Will be definitely helpful, since I want to synchronize the working folder of a git repository, and a lot of things have to be kept out of the synchronization. – CamilB Apr 10 '16 at 9:48
  • I think that meuh's answer is the best you could safely do for this. However, if you really wanted to just call rsync, you could alias the rsync command so that calling rsync actually calls a wrapper function which first checks for a local config file as you describe, and then calls the rsync binary. This is pretty similar to what meuh does, except it will affect all calls to rsync. While this means you can "simply run rsync", it may have unintended side effects. – Ryan Apr 11 '16 at 0:52

You should write your own little shell script for that. For example, "myrsync" in your PATH holding:

  if [ -t 0 ] &&
     read -p "ok? $* ? " reply && 
     [ "$reply" = y -o "$reply" = ok ] 
  then "$@"

if [ -f .myrsync ]
then ok rsync $(<.myrsync)
else echo "no .myrsync here in $PWD"

This has a function ok that tests that stdin is a terminal, then prompts you with the rsync command it has found and if you reply "y" it runs it. The rest of the script tests for a file .myrsync and if so runs the function on its contents.

  • This is awesome :) – CamilB Apr 10 '16 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.