Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to have a rsync shell script that the user will enter the folder or file to sync to another server.

i.e. - ./deploy /html/ or ./deploy /html/kuky.txt

the script will wait for the input and then will execute the rsync script please help.

share|improve this question
up vote 4 down vote accepted

Here you go:

echo "Enter file or folder path"

read target

if [ ! -e "$target" ]
    echo $target does not exist
    echo Transferring $target
    rsync -avzr $target

put this into a file called Then call bash from command line.

I suggest you look up options of rsync command. They may change behavior a great deal.

share|improve this answer
thank you! it works!! – edotan Nov 20 '11 at 18:50

Can's answer requires a user to run the script and then type the path manually, the following will allow you to use the syntax you specified in your OP:


echo -n "Transferring ${*} to server... "
rsync -az ${*} <user>@<server>:/path/to/target/ 1> /dev/null
echo "Done!"

This script will take all CLI arguments given to it as source directories/files, and send them to the server.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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