17

How do I reveal a file that I have the path for in the Terminal in Finder? I don't think that open will work for this.

Specifically I want to be able to fzf for a file and then pop it in Finder.

(I guess this would work if you get the path, chop off the file bit and then call open on the rest?)

2
  • 1
    fzf is not a default or native macOS command line utility, so you might want to expound on "Specifically I want to be able to fzf for a file and then pop it in Finder.". Oct 6, 2020 at 13:19
  • Here's a useful discussion of fzf: superuser.com/questions/817351/… Oct 7, 2020 at 13:47

3 Answers 3

40

How do I reveal a file that I have the path for in the Terminal in Finder? I don't think that open will work for this.

From man open:

-R  Reveals the file(s) in the Finder instead of opening them.

So, open -R /path/to/a/file.ext will reveal your file in the Finder...

Specifically I want to be able to fzf for a file and then pop it in Finder.

In its most basic usage the following will reveal in Finder the file selected from the execution of "$(fzf)":

open -R "$(fzf)"

The following fzf key bindings will map ctrl-r to reveal the file in the Finder and ctrl-space to a QuickLook of the file:

fzf --bind 'ctrl-r:execute(open -R {}),ctrl-space:execute-silent(qlmanage -p {})'
1
  • 2
    The fzf bindings are a great touch. Thanks!
    – Alper
    Oct 7, 2020 at 17:46
0

If you happen to have a relative path try this.

open relative/path/to/my_file.txt/..

Note the last three characters /..

This opens Finder with the parent directory of my_file.txt.

2
  • 1
    It works with relative paths, not with absolute ones. May still be worth posting it though
    – nohillside
    Oct 6, 2020 at 15:23
  • 3
    Using open -R, as in the accepted answer, is much better as it actually highlights the target file in the opened Finder window whether using absolute or relative paths, not just opening the folder of the target file, then having to look for the target file as this answer forces one to do. Oct 6, 2020 at 16:46
-2

If you're in the directory (presumably you are) type

% pwd | pbcopy

then open Finder, press Shift Command G to "Go to Folder", paste and press Return.

The open command as detailed by this answer is the fastest and easiest my opinion, I just wanted to provide you with an alternate method to highlight some features of macOS users may not be aware of:

  • pcbopy utility that sends input to the clipboard
  • Keyboard shortcut to open folder directly in Finder
4
  • 2
    This does not reveal the file.
    – Alper
    Oct 6, 2020 at 14:28
  • 2
    You know the file name right? Type the first couple of chars.
    – Allan
    Oct 6, 2020 at 15:01
  • 5
    Very weak as an answer, but very nice as a PSA for pbcopy. Oct 6, 2020 at 19:51
  • 2
    I'm looking for an automated solution not a basic user guide to macOS.
    – Alper
    Oct 7, 2020 at 17:46

You must log in to answer this question.

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