Apple - Open Finder window from current Terminal location?

Typing open . in Terminal will open the current working directory in a Finder window.


Stretch goal!

To expand on the answer above (because the more appropriate related question is marked as a dupe and can't recieve new answers)...

I've added a function to my ~/.bash_profile to handle revealing a file or directory:

# Reveal a file or directory in Finder
# ..expects only one argument
# the argument is quoted to accommodate spaces in the filename
reveal () {
   # if the first arg is a directory
   if [[ -d "$1" ]];
       then
           # ..use the argument directly
           basedir="$1"
       else
           # ..we passed a file, so use its containing directory
           basedir=$(dirname "$1")
   fi
   # basedir is a directory in now, so open will activate Finder
   open "$basedir"
}

To install the function:

  • paste/save it into ~/.bash_profile
  • source ~/.bash_profile or open a new terminal/tab

The context for my use is that I'll be browsing around using ls with tab completion, then when I find what I'm looking for, I can reveal (or cd or subl) the most recent arg, like:

ls dir/subdir<tab tab>
subsubdir  anotherdir
ls dir/subdir/anotherdir
reveal !$

If you have autojump installed, you don't even have to type the full path to the directory. You can simply type jo partialdirectoryname, and autojump will open a new Finder window in the specified directory.

I love this method, because you don't have to remember the entire directory name. Autojump keeps a list of most commonly used locations, and automatically knows which directory you're referring to, even if you only give it part of the name.