UX Design and Development course

Setting up Rsync

When creating a shell script, create a new [name].sh file. It is best to place the shell script on your /bin/ directory. This is at the root of your computer. You will probably need to use the sudo command to add a file here; sudo touch file-name

Next, write out the commands you want automate

find . -name '*.DS_Store' -type f -delete
cd ~/../../Volumes/ && rsync -avz --progress --delete Macintosh\ HD/Users/[name]/Desktop/foo Macintosh\ HD/Users/[name]/Desktop/backups

What is a backup without automation?

If you've got a website that's heavy on your web server, you might want to run some processes like generating thumbnails or enriching data in the background.


To ensure that the file you created is executable, run the following

$ chmod +x [name].sh

Manually run shell

$ sh [name].sh

To see the list of cron jobs

$ crontab -l

To edit the list of cron jobs

$ crontab -e

This example will rsync a directory [foo] to the directory [backups] on the Desktop

cd ~/../../Volumes/ && rsync -avz --progress --delete Macintosh\ HD/Users/dalesande/Desktop/foo Macintosh\ HD/Users/dalesande/Desktop/backups

This script will backup select files to my Dropbox folder

Requires that dotfiles, default, user directories be created to deposit backed up files

rsync -avz --progress --delete ~/.bash_profile ~/Dropbox/dotfiles
rsync -avz --progress --delete ~/.gitconfig ~/Dropbox/dotfiles
rsync -avz --progress --delete ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/Default/Preferences.sublime-settings ~/Dropbox/dotfiles/default
rsync -avz --progress --delete ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/User/Preferences.sublime-settings ~/Dropbox/dotfiles/user
rsync -avz --progress --delete /bin/backup.sh ~/Dropbox/dotfiles
rsync -avz --progress --delete /bin/photos-backup.sh ~/Dropbox/dotfiles
rsync -avz --progress --delete ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/User/snippets/* ~/Dropbox/dotfiles/sb-snippets

To see cron log:

s /tmp/cron.out

Full computer backup

$ rsync -avz --progress --delete ~/../../ ~/../../Volumes/[volume name]

How do I delete all Terminal mail?

I set up a cronjob a long time ago that now doesn't exist. Whenever I open up Terminal, it now says "You have mail". I have something like 100 messages that all say the same thing. How do I mass delete all of the messages?


Launch the Terminal mail app with:

$ mail

You'll see a list of all your messages. Look at the count at the top, it will say the number of messages you have. Say that number is 30. From the mail prompt, do

? delete 1-30
? q

And that should be it. Make sure do to the q after the delete 1-* command, that saves the changes to disk.