Emil11
Emil11

Reputation: 199

Find file and cd into it

I am attempting to find multiple files, then quit after the first match and then cd into this match, I have attempted:

find `pwd` -iname 'tensorflow' -type d -exec echo {} \; -quit | xargs -I{} cd {}

However, this does nothing and it won't enter into that directory.

Upvotes: 0

Views: 42

Answers (1)

KamilCuk
KamilCuk

Reputation: 140940

There is no /usr/bin/cd, it's not an executable. You have to run it in current shell, not in subshell as part of pipeline.

Do not use backticks. Prefer $(...).

find pwd? Just find ., you are already in pwd.

-exec echo {} \;? Just -print it.

dir=$(find . -iname 'tensorflow' -type d -print -quit)
cd "$dir"

Upvotes: 1

Related Questions