The typical use of diff from within a terminal (using the default Bash shell) is to compare files. However, with a little slight of hand, known a process substitution, we can use diff to compare the contents of two directories.

The syntax looks as follows:



Commands represents a single command (such as find) or a piped list of commands. The end result of using process substitution is that the commands act as a file. In the first example, the process substitution results in what looks like a file that can be fed into another command. The second example is the opposite, the process substitution enables one or more commands to act as a file for input. Let’s look at how we can use process substitution for comparing directories.

Let’s say we want to compare the contents of the two directories above. The screenshot was captured from Finder, and in this case, provides a concise view of each directory. However, if the directories are not as conveniently located (in the same sub-directory) or have many more files, or if you need to compare directories from within a terminal, then you could run the following from a terminal:

$ diff <(find tmp1) <(find tmp2)

Here we use the find command to walk through the directories. Using the process substitution, the results of the find command look as though they are files, which enables us to feed both into diff.

You can learn more about process substitution on the Bash man page at the Apple Developer Connection.

Root is the uber system account. Although handy at times (for example when installing applications), it’s generally recommended that root not be used as your everyday login. What follows are some options for working as root.

If you need to run a command as root, you can use the sudo command. For example, to run the script for daily system maintenance, you can run this command (the $represent the terminal prompt):

$ sudo periodic daily

Now that’s all well and good, however, it’s generally applicable only for one command. What if you are in a terminal and want to login as root to do some larger scale maintenance or system work? Try this:

$ sudo -s

This command will enable the root account and update your prompt as shown in the figure below:

The above screenshot assumes you are using the bash shell and have admin rights on the account you are logged in with. The $ typically represents a user account whereas # represents root.

The last option is to create/enable a root account, thus you can login (when restarting/rebooting) as root. This approach offers the most flexibility and power, however, use with caution as there are no limits to what (damage) you can do.

Root account option #1: Enter the following from a terminal:

$ dsenableroot

You’ll be prompted for your (current) password, as well as the new root password.

Root account, option #2: Enter the following from a terminal:

$ sudo passwd

You’ll be prompted for the same series of passwords as above.

Root account, option #3: Follow the steps below:

- Start the Directory Utility application (/Applications/Utilities/Directory Utility)
- Click the lock icon in the lower left corner (to unlock it)
- From the Edit menu (across the top of screen), select Enable Root User

To wrap up this post I was planning to show you how the login window changes when a root account is enabled. Unlike other accounts on your system where a name is typically displayed as one of the login options, the root account is not listed as one of the options (for security reasons).

However, getting a screenshot of the login screen is a considerable feat. This is a great segue to a post coming next week where I’ll show the tricks that I tried for capturing the elusive login screen and I will pose an intriguing challenge for you…

One of the defining concepts of working on a Mac is that things (usually) work just as you think they should. This is the culmination of good design translated into working code. The short video that follows is an example demonstrating how easy and intuitive it is to change the icon for an application. Believe it or not, it” onclick=”return TrackClick(”,’javascript%3AlynkVideoPop%28719%2C’)”s as simple as copy/paste.

This is a great trick to have up your sleeve when working with development tools that create a default icon, for example the Script Editor. With this approach you can quickly change an icon to reflect that something visually represents what the application does. And to help, do a quick search on Google for Mac OS X icons and you” onclick=”return TrackClick(”,’javascript%3AlynkVideoPop%28719%2C’)”ll be amused for hours…

Working with multiple monitors is a must when doing any serious coding work. Code on one side, output on the other. No more swapping applications from the foreground to background.

Mac OS X make working with multiple monitors a snap: plugin in the secondary monitor, open System Preferences, click on Displays, click on the Arrangement tab and arrange the displays by dragging and dropping. That’s it. In the figure below the larger box is the secondary monitor (larger view area) and the smaller is my laptop.

There is one default setting that I want to mention here that hopefully will save you some time. When you set up an additional monitor the menu bar stays on the original display. Depending on your arrangement, this may be no worry. In my case I wanted the secondary monitor to be the primary display. When working on an application in what is now my primary display, it’s anything but intuitive to move the mouse back over to the laptop display to click a menu item.

I spent some time searching for a tip, trick or hack to fix this little problem, to no avail. I went back into the system settings any number of times looking for a preference setting. I even did a search for a Mac Defaults option to specify where the menu should land. Again, no luck.

Here’s the punch line, the fix was so obvious, it wasn’t obvious. If you look closely at the figure above, notice the second line in the description area…”To relocate the menu bar, drag it to a different display.” Heh, was that there the whole time…??

So here’s the tip: to move the menu bar simply drag-n-drop as you prefer.

Okay, so here’s where I have a question for you. I recently upgraded to Leopard (10.5), and I’m curious if this feature existed on Tiger (10.4)? Essentially I’m looking for an excuse as to why I didn’t see the obvious solution to my question, right in front of me. Maybe you can help me out here :)

MacFUSE is an open source project that simplifies the process of adding a file system to Mac OS X. If you’ve ever had an inclination to create a file system, or thought that a file system like “interface” would be an intuitive approach to solving a problem, yet, upon delving into what it takes to create a kernel extension, you opted to rethink your idea (or at least the approach) here’s where MacFUSE comes in, effectively offering an API to implement a file system.

FUSE (file system in user space) was born and bred as a Linux tool. MacFUSE is a port of FUSE to the Mac by Amit Singh. From the highest level, there are two key aspects to FUSE. First and foremost (without it you have nothing) the dynamically loadable kernel extension. This is where all the hard work (aka magic) takes place. The second aspect is the API, not unlike any other API you’ve worked with, the FUSE library offers an interface to communicate with the kernel extension. Using calls such as read, open and write, working with your own file system on FUSE becomes a rather trivial undertaking.

Following are a few examples of application using MacFUSE:

  • SpotlightFS: an application that dynamically generates smart folders from Spotlight queries
  • SSH FileSystem: file system client based on the SSH

To learn more about MacFUSE, you can watch this video of Amit reviewing his MacWorld 2007 presentation.

When working inside a terminal window, there’s a quick shortcut you can use to open a file (read, launch an application on a specific file or set of files). The beauty of this trick is that the command will work as if you clicked on an application icon(s) in Finder. For example, if you request to open a file with an extension of xml, the application associated with that extension will be started and the specified file will be passed to the application.

The command I am referring to is open; read on to see a few examples:

From a terminal window, to all the files with a “.rb” extension (in the current directory):

> open *.rb

To launch a browser at a specified URL, try this:

> open

And to open Finder in the current directory:

> open .

You can get more information about using the open command by viewing the manual page:

> man open