Hacker News new | ask | show | jobs
by adventureloop 4544 days ago
Another really useful command is the open

    $ open filename.png
    $ open .
    $ open -e filename.txt
    $ open -a Pixen filename.png
The first command will open the file with the default application.

Open . will open the current directory in finder, which I find very helpful.

The -e flag will open the file in textedit.

The -a will open the file in the given application name.

3 comments

Under Linux there is a similar command: xdg-open
or gnome-open.

On Windows the equivalent is start (e.g. start C:\ )

I use start all the time, but also frequently curse at its stupid argument grammar and its interaction with auto-quoting on auto-completion. For example, type

  start C:\Doc
Next, hit tab to get

  start "C:\Documents and Settings"
Now, hit return, and watch a new command window open with title "C:\Documents and Settings".

Reason? If the first argument is a quoted string, it is used as the title of the window being opened (http://www.microsoft.com/resources/documentation/windows/xp/..., http://stackoverflow.com/questions/154075/using-the-dos-star...)

If you ever use start in batch scripts, pass a dummy first argument of ""

You can use `explorer`, which doesn't exhibit this behavior:

    explorer "C:\Documents and Settings"
does what you'd expect.
I think xdg-open defers to gnome-open/kde-open/... depending on what DE is currently running. Not sure about that. Anyway, xdg-open should be installed anywhere where any kind of DE is installed.
For the lazy:

  $ echo "alias o='xdg-open'" >> ~/.bashrc
open -n is also useful: Allows you to run two instances of the same app at a time.
Thank you for this! It always frustrated me that I couldn't open multiple videos at once in VLC.
Try "open -h NSString.h"...
Also very useful for similar use cases is qlmanage.

    $ qlmanage -p <file>
This seems to run whatever code usually runs when you hit [space] on a filename in a Finder window. (Except that it outputs a bunch of debugging information.) Under what circumstances is that any better or more useful than "open"?
Correct (man 1 qlmanage). Depending on the type of file, it is usually faster to open quicklook than opening the file in its default application, especially if you just want to take a look and you don’t actually need to edit the file.
You can hide the debugging info by redirecting the output streams.

    $ qlmanage -p <file> &>/dev/null
Because it essentially acts like quick look for the terminal.