Home > Enterprise >  Find file and cd into it
Find file and cd into it

Time:01-11

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.

CodePudding user response:

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"
  •  Tags:  
  • bash
  • Related