11.5. Exercises

  1. With the Terminal application, use Bash interactively to create a compressed archive of all the files of a particular type (that is, with a particular extension) located in your home directory or subdirectories.

    First locate the files with the find command and copy them to a temporary directory. Rather than using the standard cp command, which neglects to copy resource forks on versions of Mac OS X prior to 10.4, use the CpMac command in the /Developer/Tools directory. To learn more about this command, see the CpMac man page. Use ditto to compress the archive, and mv to move it to a backup directory.

    Refer to the man pages of the various commands to learn how they are used.

  2. Convert the interactive commands you used to complete Exercise 1 into a backup script. You can use the history command to see what commands you typed. For more information, see the history man page.

    Restructure the commands to make the script more readable and robust if necessary, and don't be afraid to introduce shell programming constructs such as conditional branches and functions. Have the script check for errors and send you an email you if one occurs. (Hint: see the man page of the mail command.)

Get Beginning Mac OS® X Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.