The Terminal in OS X

By Blane Warrene
We teamed up with SiteGround
To bring you the latest from the web and tried-and-true hosting, recommended for designers and developers. SitePoint Readers Get Up To 65% OFF Now

The Terminal utility is a great feature within Macintosh OS X, and with the Panther version OS, standardized on the Bash shell. Bash is one of the most commonly found and popular shells in Unix variants, including Linux.

Fortunately for those of us who migrate between operating systems on a regular basis, when returning to the Mac, Bash functions much the same as anywhere else.

If you use OS X as your primary workstation os, you can access local and remote servers with shell access and perform all of your system administration and other efforts from the Terminal. However, there are a few areas unique to the Mac that may come in handy.

For starters, Terminal is found in the Applications folder, within Utilities. if you are using the Terminal to work on your OS X system, some directory structures are mildly different. As an example, several directories are actually aliased inside of /private, such as /etc and /var. To review these, you can type ‘man hier’ in the Terminal for an overview.

Additionally, sudo (the ability to become a superuser for a single command line operation) is automatically on and enabled for the admin user of the machine. In essence, to edit a file that is privileged, a user can type ‘sudo vi /private/etc/httpd/httpd.conf’, is prompted for their admin password and is temporarily elevated to superuser for the event.

You will also find the files you create on the Mac have resource forks associated with them. The explanation of resource forks is a long one so I will not go into it here – however a great overview can be found on the Wikipedia.

Normally, these are not an issue, even across platforms as of Panther, with support for Windows-friendly attachments built into the system and Microsoft’s Office more capable of packaging documents for interoperability. However, from a developer or administrator’s perspective, many file operations may occur in the Terminal. Apple has included some utilities to accommodate the resource forks.

For example, one can use traditional shell programs like cp and mv to work with files and directories. However, those files will be copied or moved without resource forks and could potentially lose data or important file information if restored and accessed at a later date.

Ditto, CpMac and MvMac resolve these technicalities. The three work much like cp and mv, in that they copy or move files or directories to new locations. Ditto has a handy option for preserving resource forks by using ‘ditto -rsrc sourcefile destinationfile’. CpMac and MvMac automatically preserve metadata and forks when used. One limitation is MvMac does not work across filesystems and volumes other than the one mounted as primary.

For backup purposes, ditto or CpMac will work fine, preserving the important resource data while getting your files and directories moved onto remote filesystems or external volumes such as cd-rw or hard drives.

We teamed up with SiteGround
To bring you the latest from the web and tried-and-true hosting, recommended for designers and developers. SitePoint Readers Get Up To 65% OFF Now
  • I’m not a big fan of the default Terminal app – I dislike the way it handles logging out (leaving me to manually close the window) and I’ve had it crash on me a few times. I use iTerm instead:

  • Vanish

    You can change the behavior of Terminal leaving the window open when logging out through it’s preferences. I have never had Terminal crash, but have experienced such when using iTerm. If Apple would add tabs to Terminal I’d be in heaven.

  • Amorya

    Tabs? Sacrilege!

    Tabs are way too MDI for me. The main metaphor for the Mac desktop has always been one document one window. I’d rather stick as close to that ideal as possible :)

  • Chris

    Tabs? Sacrilege!

    Clearly the Apple metaphor was broken for Safari? I aggree with Vanish, tabs in the Terminal would be great.

  • Eric

    Time to evolve to tabs. :-)

  • nick

    well, having the same thoughts as the above posters, I just found a tabbed terminal client — I am disappointed that it doesn’t emulate apple’s auto-titling of windows, and thhat they used the standard tab view from the macOS widget set, but it does the job.

  • jed

    Terminator works pretty well too…