205

If I am in a specific path in a Terminal window, how can I open that same window in a new Finder window?

Note: This is the opposite of opening a Terminal from Finder.

0

7 Answers 7

261

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

8
  • Thanks, that was exactly what I was looking for. I'd seen it before, but forgot it. Commented Jul 30, 2011 at 22:14
  • Looks like this is broken in 10.9 Mavericks. Any workaround? Commented Nov 11, 2013 at 5:19
  • @WolfgangFahl It still works for me in 10.9 Mavericks. Commented Nov 11, 2013 at 21:25
  • @WolfgangFahl Was your Mavericks install a fresh install or an upgrade? My upgraded install of Mavericks lets me use this command.
    – user15819
    Commented Feb 22, 2014 at 3:15
  • of four Mavericks installs i did the problem only happend once for an upgrade install. All otheres were fine. The problem with the upgrade install also went away after a while. Strange ... Commented Feb 22, 2014 at 16:30
10

Stretch goal!

To expand on the answer above (because the more appropriate related question is marked as a dupe and can't receive 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
reveal() {
  # grab the first arg or default to pwd
  local basedir=${1:-${PWD}}

  if [[ -f "$basedir" ]]; then
    # ..we passed a file, so use its containing directory
    basedir=$(dirname "$basedir")
  fi
  # basedir is a directory in now, so open will activate Finder.
  # The argument is quoted to accommodate spaces in the filename.
  open "$basedir"
}

…one liner:

reveal() { local dir=${1:-${PWD}}; [[ -f "$dir" ]] && dir=$(dirname "$dir") || true; open "$dir"; }

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 !$

Thanks to @nohillside, @Ed Randall, and Community for improvements!

3
  • 2
    worth noting that the only thing that this adds to open . is allowing us to pass a filename and get the containing directory :)
    – ptim
    Commented Oct 9, 2015 at 2:29
  • 1
    Good plan, I simplified and enhanced this slightly: (1) named the function finder; (2) first line inside the function local basedir=${1:-${PWD}} (3) shortened the if/else to if [[ -f ${basedir} ]] ; basedir=$(dirname ${basedir}) ; fi
    – Ed Randall
    Commented Mar 11, 2021 at 9:33
  • Tx @EdRandall! Maybe someone will come along and help me understand how to also allow piping to this function without waiting for input when stdin is empty 😆! cf unix.stackexchange.com/questions/33049/…
    – ptim
    Commented Mar 25, 2021 at 11:03
7
open .

As a nice addition, add an alias in .bash_profile or .bash_aliases if you have one.

alias finder='open'

Then you can use finder . which I think is more intuitive.

0
5

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.

1
  • I do have autojump installed but I get jo command not found Commented Mar 21, 2017 at 16:25
3

Typing open . in Terminal will open the current working directory in a Finder window.
But there is also an alternative version

open `pwd`
1

I am afraid just open is not enough, for example, if you have a directory named /Users/hanley/repo/iconnect/MobileDevice.xcframework, you will get error after you use open /Users/hanley/repo/iconnect/MobileDevice.xcframework:

No application knows how to open URL file:///Users/hanley/repo/iconnect/MobileDevice.xcframework/ (Error Domain=NSOSStatusErrorDomain Code=-10814 "kLSApplicationNotFoundErr: E.g. no application claims the file" UserInfo={_LSLine=1608, _LSFunction=runEvaluator}).

So I advise we can use open -b com.apple.finder `pwd` to open current directory in Finder.app.

For more convenience, you can alias it with alias ofd='open -b com.apple.finder `pwd`', then ofd command will directly open current directory in Finder.app

For more usage of open, please read man open

1
  • This worked in situations the previous answers didn't. Gracias!
    – lodeOfCode
    Commented May 17 at 13:21
0

I know this is very old thread. At the terminal typing open . opens the current directory as others stated. In addition, the following will reveal (but not open) files/folder open -R . A combination of both becomes really powerful and time saver. You can also open all the Text files with open *.txt command in the current directory. How cool is that!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .