Is there a way to find a specific file and then change into the directory containing it in one go?

Posted by bergyman on Stack Overflow See other posts from Stack Overflow or by bergyman
Published on 2010-05-06T18:53:16Z Indexed on 2010/05/06 19:08 UTC
Read the original article Hit count: 207

Filed under:
|
|

I'm looking for a way to find what I know will be a unique file, and then change into the directory containing that file. Something along the lines of:
find . -name 'Subscription.java' | xargs cd
Or:
find . -name 'Subscription.java' -exec cd {} \;
I know this won't work because it's both trying to cd supplying the entire absolute path, which contains the file, and also because xargs can't do any built in shell commands...but you get the point of what I want to accomplish.

© Stack Overflow or respective owner

Related posts about linux

Related posts about command-line