Header Image - charles newman's blog

Category Archives

18 Articles

Mac OS X – Easy way to do a hex dump of a file

by Charles Newman

Occasionally, as a developer, I have a need to do a hex dump of a file to inspect extraneous tab characters, extra newlines, etc. On the Mac, you can easily do this on the command line.

With this command, you can get a nice, side-by-side hexadecimal and ascii view of the first 128 bytes of a file without downloading any shareware or other development tool:

hexdump -C -n128 myfile.ext

Mac OS X – Create an Alias by Clicking and Dragging

by Charles Newman

An “alias” in OS X is a symbolic link, or essentially a reference to another file. It is not a copy of the file, just a pointer to it. So for example, if you find yourself digging through folders in the Finder for the same document every day, it might be more efficient for you to place an alias of the file on your desktop.

To do that, simply drag it from the Finder window and hold down the Cmd (or Apple key) and the option key while you drag. Let go and you have your new alias.

You can also create an alias by selecting the file (single-click) and then typing Cmd l (that’s a lower case L). This will create an alias right next to the file it references. You can then drag the alias, or cut and paste it anywhere you like.

Mac OS X – Starting/Stopping Apache

by Charles Newman

Every Web developer needs to test files with a Web server and the most convenient way to do that is to run a Web server locally on your development machine and access it via localhost (127.0.0.1). One of the reasons Macs make such great dev machines for Web developers is they come standard with almost everything you need: Apache, MySql, Python, Perl, PHP, Java, etc.

From a Terminal window, these commands will start or stop Apache:

  • sudo apachectl start
  • sudo apachectl stop

After you’ve started Apache, browse to this address and you’ll see the standard Apache page:
http://localhost

The default location of the web site files on your file system is called the document root, and that is here:
/Library/WebServer/Documents

If you use this address:
http://localhost/~yourname

Those files are here:
/Users/yourname/Sites

Trouble shooting
If the default Apache page doesn’t load when you click http://localhost, check to make sure the Apache process loaded. You can type this into a terminal window to verify that Apache is loaded:

ps acx | grep -i 'httpd'

If you don’t see anything returned that means Apache failed to load. To find out why, run the Console app (you can find it in /Applications/Utilities or just type “console” into Spotlight). Click “All Messages” and you should see something like this:

httpd: Syntax error on line 117 of /private/etc/apache2/httpd.conf...

In that case just open the httpd.conf (you will probably need to “sudo vi httpd.conf”) and make adjustments. You may need to comment out some mods that are failing to load, or you need investigate what is wrong with the offending mod.

Mac OS X – Show Hidden Files in the Finder

by Charles Newman

The Finder, by default, does not show you every file on your system. You can tell it to show file extensions in the Preferences pane, but there is no preference for showing hidden files. Sometimes you want to edit your .bash_profile in something other than “vi” :)

Launch the Terminal app and:
1) Type this command in a Terminal window:
defaults write com.apple.finder AppleShowAllFiles TRUE
2) Restart Finder:
Option+Cmd Click the Finder Icon in the dock and select "Relaunch"

Mac OS X – Create a Zip File and Give it a Password

by Charles Newman

You can do this on the command line (in the Terminal Application) without any other software.

zip -r -e misc.zip ./misc

The command above takes the entire contents of the ./misc folder (-r means recursive) and creates misc.zip in the current directory.

to unzip:

unzip misc.zip (it will prompt you for the password)

To unzip from the Finder, you’ll need Stuffit Expander (currently there is a free download at http://www.stuffit-expander.com)

Mac OS X – “The operation could not be completed because the item is locked”

by Charles Newman

Have you ever gotten this annoying message while emptying the trash from the Finder menu:

The operation could not be completed because the item is locked

When I first started using a Mac, I would get this message, say a bad word, and then go hunt down the file and do a “chmod” on it or unlock it via Cmd-I in the Finder.  Then I discovered this:

Hold down the option key as you select “Empty Trash” from the Finder menu and OS X will delete the locked files without annoying you.

Taking Screenshots in Mac OS X

by Charles Newman

I can never remember these for some reason, but I seem to need one of them every 6 months or so:

  • Command-Shift-3: Take a screenshot of the screen, and save it as a file on the desktop
  • Command-Shift-4, then select an area: Take a screenshot of an area and save it as a file on the desktop.
  • Command-Shift-4, then space, then click a window: Take a screenshot of a window and save it as a file on the desktop.
  • Command-Control-Shift-3: Take a screenshot of the screen, and save it to the clipboard.
  • Command-Control-Shift-4, then select an area: Take a screenshot of an area and save it to the clipboard.
  • Command-Control-Shift-4, then space, then click a window: Take a screenshot of a window and save it to the clipboard.