This is macOS specific, but seems too unixy to go in the Ask Different community.

In Terminal, I can pwd, copy the result, and type open and paste the result and the folder will open in the Finder, but

pwd | open

prints the help documentation for open. Why doesn't piping work but pasting does?

  • that will only work if open expects you to type the directory name after you press enter. – Jasen Jul 23 '16 at 4:32
  • 9
    Also, this should (not a mac user) work: open . (for the current directory) – user137998 Jul 23 '16 at 10:44
  • @BharadwajRaju open . works and does seem the easiest. ty. – Chuck Jul 23 '16 at 13:00

I don't have a Mac so I can't test it, but the solution should be something like:

open "`pwd`"

Not all programs take their input from stdin which would be necessary for the pipe to work.

  • 1
    The double quotes are unnecessary. – tbodt Jul 23 '16 at 18:50
  • 4
    @tbodt: Try it in /var/tbodt's files. – Julie Pelletier Jul 23 '16 at 19:00
  • 2
    @tbodt: How would any shell know if the space used is to separate arguments or part of an argument? – Julie Pelletier Jul 23 '16 at 19:06
  • 2
    @jamesdlin: Go complain on the bash development project, but don't forget to also go bash all older shells and most newer shells while you're at it. Over and out! – Julie Pelletier Jul 23 '16 at 19:34
  • 1
    @JuliePelletier I'm just saying that you claim it's impossible for any shell, but shells such as fish behave exactly as tbodt describes. – jamesdlin Jul 23 '16 at 19:35

The open utility on macOS does not read from standard input, but take its arguments from the command line.

To open the current working directory, you would have to say

$ open "$( pwd )"


$ open "$PWD"

or simply

$ open .

as pointed out in the comments below.

With the -f flag, open can be made to read from standard input, but only to open whatever it receives in the default text editor.

  • 1
    If the shell is (t)csh, you'd want open $cwd:q instead. And open (pwd) /open $PWD if it's fish – Stéphane Chazelas Jul 23 '16 at 7:46
  • 1
    @StéphaneChazelas I believe the default shell on Darwin is bash, but it's always good to see solutions for other shells too. – Kusalananda Jul 23 '16 at 7:55
  • For completeness, with rc, es, akanga shells: open `pwd or open `{pwd} – Stéphane Chazelas Jul 23 '16 at 10:19
  • 5
    Or you can use the syntax- open . for the current working directory or the parent directory open .. or up two directories open ../.. and so forth. – fd0 Jul 23 '16 at 10:46
  • @StéphaneChazelas: Why would $cwd:q be preferable to "$cwd" in a csh-related shell? – G-Man Says 'Reinstate Monica' Jul 24 '16 at 2:18

The other answers are totally correct. If you want an easy shorthand, you can do as @fd0 proposed, and just use

open .

to open the current directory. The current directory is named . (a single dot) in Unix, the parent directory .. (two dots).

pwd | xargs open

xargs shoves its standart input into the arguments of its first argument.

  • 2
    That's only if the current working directory path doesn't contain blanks or newline or single quotes or double quotes or backslashes. – Stéphane Chazelas Jul 24 '16 at 4:06
  • pwd | xargs -d '\n' open – belkka Mar 17 '19 at 4:23

You can use a pipeline with -f to open the content of the previous command in a Text Editor. This just applies for text editors. For other apps you'll need to use the suggestion in the other questions.

For example:

ls | open -f

This would open your default text editor with the ls output content.

You can also specify the text editor to use using -a:

ls | open -a 'Atom' -f

This would open Atom with the ls output content.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.