O'Reilly logo

Beginning Mac OS® X Programming by Drew McCormack, Michael Trent

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.)

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required