Rio_Nyx
Rio_Nyx

Reputation: 94

Is there any way in which i can goto a directory found out using "find" command?

I would like to use a command that change the current working directory to the one i find out using the "find" command.Is there any way that I can do that on a single line in bash? I would like to use a command that change the current working directory to the one i find out using the find command.Is there any way that I can do that on a single line in bash? I want to go to a directory called "mydir".I only know that it is somewhere in "documents". I want to change my current working directory to "mydir". I know that I can know the path using find -name mydir.

Upvotes: 0

Views: 305

Answers (1)

karakfa
karakfa

Reputation: 67567

this should do..

$ cd "$(find . -type d -name myDir -print -quit)"

-quit to ensure at most one value is returned (and finish looking after first match), may not be supported in all finds. Otherwise you need to filter the result but will take longer.

Upvotes: 3

Related Questions