home research publications numbers and models contacts computer links
Here are some things I've found useful for OS-X. Enjoy. Contribute if you wish!
Eric Nodwell, eric.nodwell[AT]gmail.com, July 2007
For those times when you would rather move something to the Trash than erase it completely (rm is final), you can use this script: trash.
Features:
You can specify multiple arguments.
It will expand wildcards such as * ? . .. ~
It won't clobber anything already in the Trash. It follows the (re)naming convention that OS-X uses when you move something into the Trash with the same name as an existing item.
Installation
Put it in a folder on your path and make sure it is executable.
Other similar utilities
There is The Born Again Remove Function, which "emulates the GNU rm function, except that it moves files to the user's Trash directory, instead of unlinking them". Aesthetically, I don't like that approach. Options such as -f and -r are nonsensical when moving something to the Trash.
I've always wondered why OS-X doesn't have size/age limits on the Trash. Performance issues? Who knows?
This script will do that for you: strash .
This is a modified version of a trash-cleaning script originally written by Frederic Connes for libtrash. I've modified it to work in OS-X . Actually it should probably be rewritten entirely in Perl or Python or something, but I can't really be bothered, and it has proven over time to be quite reliable, a property which is very important in a script which runs without user intervention and makes liberal use of rm.
Installation
Put it on your path and make it executable.
strash makes use of tac and numsort (see below), so make sure you install those as well.
To have it run automatically, make a short script like this in /etc/periodic/daily. (I called it 777.cleantrash). Remember to make it executable (chmod +x /etc/periodic/daily/777.cleantrash).
#!/bin/bash /usr/bin/nice /usr/local/bin/strash --age 60d --quiet /usr/bin/nice /usr/local/bin/strash --filesize 2G --quiet /usr/bin/nice /usr/local/bin/strash --size 5G --quiet
You can use rsync to easily backup and synchronize data. Since rsync only copies over files which have changed, it can be very fast to run after the first time.
Example 1. This script synchronizes my entire home folder to a sub-folder on another local mac. I exclude the Pictures and Music directory.
It will overwrite or delete files on the destination machine which are different or not present. However, it will save anything it clobbers to the Trash folder on the destination machine, so even if you screw up, it's safe to use.
Notice that this script can only be run when I'm on the same local network as the grossmuenster host.
#!/bin/bash
BACKUPDIR=~/
TARGETHOST="us@grossmuenster.local"
TARGETDIR="~/Documents/eric/ibook/"
INCRDIR="~/.Trash/sync_ibook_deleted_"`date +%Y%m%d_%H%M`
rsync --archive --delete -v $BACKUPDIR ${TARGETHOST}:"${TARGETDIR}" \
--exclude .Trash/ --exclude Cache/ --exclude Caches/ --exclude Music/ \
--exclude Pictures/ --backup --backup-dir="$INCRDIR" -a
Example 2. This is the inverse script to Example 1. When I've been working on grossmuenster, I run this script to sync the changed and new files back to my iBook.
#!/bin/bash
BACKUPDIR1=~/Documents/eric/ibook/Documents
BACKUPDIR2=~/Documents/eric/ibook/Sites
TARGETHOST="eric@thumbelina.local"
TARGETDIR="~"
INCRDIR="~/.Trash/sync_imac_deleted_"`date +%Y%m%d_%H%M`
rsync --archive --delete -v $BACKUPDIR1 $BACKUPDIR2 \
${TARGETHOST}:"${TARGETDIR}" --backup --backup-dir="$INCRDIR" -a
Installation
Put the script somewhere on your path and make sure it is executable.
Tip
Use the --dryrun flag to make sure rsync is going to do what you expect it to.
The script is here: backup-rsync .
This script will backup your /Users directory to an external hard disk, keeping it synchronized. After the first time it will only transfer files which have changed, so it doesn't take a long time to run. It will automatically mount and unmount (eject) the external drive. It also disables Spotlight indexing on the backup volume, so your computer doesn't waste time indexing it, and Spotlight won't annoyingly find files in you backup when you search.
Installation
Put it somewhere on your path and make it executable.
Prepare your hard disk: I suggest you format your external hard disk with the HPS+ file system. You must give it the name Backup. (That's how the script identifies which external hard disk to use.) Then you should "Get Info" on the Volume and make sure "Ignore Ownership" is not selected.
If you want the backup script to run daily, make a link to it in /etc/periodic/daily, something like this:
ln -s /usr/local/bin/backup-rsync /etc/periodic/daily/900.backup-rsync
If you have it running automatically, I suggest verifying occasionally that it is operating correctly. Have a look in /var/log/daily.out. That's where you'll find the output of the backup script.
Suggestion: Don't use just one hard drive for backups. You should devise a system where at all times at least one backup is physically in a remote location. For this you need at least two external drives. Using this script, it's very simple - you just swap the drives on a schedule. You don't need to do anything other than physically unplug one and plug in the other. (I do also "eject" the new one when it appears on the Desktop, but this is not necessary.)
The script is here: tac .
This script emulates the GNU utility tac, which prints out the lines of a file (or multiple files) in reverse order. It is present by default on many Unix systems and some scripts expect to find it. It is also just generally useful sometimes.
Installation
Put it in a folder on your path and make sure it is executable.
The script is here: numsort .
The sole reason for this script is that the OS-X implementation of sort sometimes incorrectly sorts things when you want it to sort numerically (i.e. with the -g flag). I've submitted a bug report to Apple, but as of July 2006, it's not fixed yet. It is not fully featured as sort, since it is intended to be a limited work-around for a specific issue.
Usage
Accepts -k and -r arguments the same as for sort. Assumes a -g flag, which you can include or not.
Assumes the field separator is a single space.
Installation
Put it in a folder on your path and make sure it is executable.