1

Is there a way to opend found directories (via find) all in one command?

One of the things I tried to study several times and never been able to really get, is the effective use of pipe: is it maybe useful for this?

I tried things like:

find . -type d -name ".dir-name" | open

but it doesn't work. open is the OSX command to open a file in the associated application (Finder for directories).

3
  • What do you mean by open? Open it in a file browser? Or change the working directory to it? – Turion Feb 7 '14 at 15:45
  • Hi! I mean open the directory with finder – Luca Reghellin Feb 7 '14 at 15:57
  • The reason why the pipe doesn't make sense here is because the pipe will send the output of find to the input of open, but you would have give it to open as a command line argument. – Turion Feb 7 '14 at 16:11
4

Use -exec:

find . -type d -name ".dir-name" -exec open {} \;
6
  • That's nice. But is open an actual command? – Turion Feb 7 '14 at 16:09
  • 1
    According to some doc I found on the web, open is the command on OsX which opens a directory with finder. – JPG Feb 7 '14 at 16:15
  • Ah, that makes sense! – Turion Feb 7 '14 at 16:16
  • Yes, I often use open [dir/file path] on osx. Thank you JPG. I often see that "{}" and "/" after -exec and similar: what does it mean? – Luca Reghellin Feb 8 '14 at 11:45
  • 1
    See man page for details. {} is replaced by the name of the file found; the ; is the end of the command and must be escaped. If you replace it with +, the command is called with all the found files passed at the same time; some programs support it, others not. – JPG Feb 8 '14 at 11:59
3

If you really need to use a pipe this should work:

find . -type d -name ".dir-name" | xargs open

I highly suggest using -exec instead, but there you have it.

0

I don't use OSX, but try this:

for dirname in `find . -type d -name ".dir-name"`; do open ${dirname}; done;

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.