Carpetfizz
Carpetfizz

Reputation: 9189

Unable to copy files from directory in shell script

I'm writing a shell script on MacOSX for the first time, and I'm a little stuck. I'm creating a website, and wanted a simple way to manage updating my files from my git repo to the localhost server. It's also just an excuse to learn shell scripting. Here's what I have so far:

#!/bin/bash
echo "Removing old Files..."
rm -r  /Library/WebServer/Documents/ServerObserver/*
echo "Copying new Files to WebServer"
cp -r /Users/ajay/Documents/ServerObserverRepo/* /WebServer/Documents/ServerObserver/
echo "Done!"

The removing part works fine, but copying does not work. I get this message in my Terminal:

usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file target_file
       cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file ... target_directory

Of course, it didn't copy either. Any help would be appreciated!

Thanks!

~Carpetfizz

Upvotes: 0

Views: 3808

Answers (2)

dannysauer
dannysauer

Reputation: 3877

You should consider rsync, as in

rsync --delete -a /Users/ajay/Documents/ServerObserverRepo/ /WebServer/Documents/ServerObserver/

that removes the need for the rm command and the cp command, and only copies the changed files / removes the deleted ones. :)

Upvotes: 1

Satya
Satya

Reputation: 8881

change

cp -r /Users/ajay/Documents/ServerObserverRepo/* /WebServer/Documents/ServerObserver/

to

cp -r /Users/ajay/Documents/ServerObserverRepo/* /WebServer/Documents/ServerObserver/.

Upvotes: 1

Related Questions