Forwarding Address: OS X

Tuesday, September 21, 2004

Over at 43Folders, Merlin has been soliciting tips for command-line beginners. I started to post something in the MT comments box, but why not post it here instead? With that, my random tips:

Learn about command-completion and history features. These save a tremendous amount of typing, prevent all kinds of stupid errors, and generally make you feel like a whiz. For example, to list the contents of the Applications folder, type ls /A[tab][return]. Cool, yes? History keeps track of the commands you've already run, so you can call up the last thing you typed and edit it for example. History is generally browsed via the up and down arrrows.

Play with things that cross the GUI-CLI divide, such as typing open . in the shell to open a Finder window showing the current directory; or the "Open Terminal Here," "Run Terminal Command Here," or "Run Terminal Command With" commands in LaunchBar; or their analogues in QuickSilver.

Explore fun hidden stuff in the shell like the /usr/share/calendar files or the cal command.

Get a feeling for how grep works with experiments like grep '^foo' /usr/share/dict/words or grep 'a.*b.*c.*d.*e' /usr/share/dict/words

Type >console in the username field at the login screen and you'll go directly to the shell.

Copy some text to the clipboard and type pbpaste | say

Read manpages, but also Google the name of the command plus the word "examples". Unix manpages often suck when it comes to providing examples.

Have fun. Take small bites. Don't worry about learning it all. Nobody learns it all.

8 Comments:

  • History searching is awesome. But there's a great way to access it. These codes in an .inputrc file in your home-directory will bind history-search-backward to the up-arrow key and vice-versa.

    So now your command line functions as a filter. Type the start of the command you want, eg:

    $ssh

    Now hitting the up-arrow will scroll through only those entries in the history file that start with ssh, and hitting down will go the other way through them.

    "\e[A": history-search-backward
    "\e[B": history-search-forward
    "\e[C": forward-char
    "\e[D": backward-char

    # alternate arrow keys (VT100 application-keypad mode)

    "\eOA": history-search-backward
    "\eOB": history-search-forward
    "\eOC": forward-char
    "\eOD": backward-char

    By James, at 6:12 PM  

  • Great tip, thanks. I've been meaning to look up how to enable that.

    By pbx, at 6:48 PM  

  • You can make tab completion even more useful by creating a .inputrc file with the following lines:

    set completion-ignore-case on
    set show-all-if-ambiguous on

    You can then enter a partial name in any case and it will work and you can hit tab to get a list of all matching items.

    By Mike, at 7:30 PM  

  • I don't think the '>console' login works anymore. at least it doesn't on my ibook and my wife's. does it work for anyone out there running panther?

    I care, because I would like to be logged in to aqua, use fast user switching, log in on '>console', then start a full screen X11 session.

    now I simply run X11 in full screen mode, but that quickly borks up aqua to where command-tab no longer functions. respawing the dock and the finder fail to fix it, the only solution I've found is to log out and back in.

    By Anonymous, at 9:07 AM  

  • This post has been removed by the author.

    By pbx, at 9:26 AM  

  • I've never had trouble using the '>console' shell login method via a regular login window in 10.3. Pretty sure it works in Tiger Preview, too. -sjk

    By Anonymous, at 6:24 PM  

  • I just checked, and you're right, it still works fine in 10.3. Where it doesn't work is from the Fast User Switching login window.

    By pbx, at 7:56 PM  

  • I'm new to Unix (OS X). Thanks, there are some sweet tricks here!

    By TeoZilla, at 6:15 PM  

Post a Comment

<< Home