I’m searching for a config folder, and trying to change to that directory:
find . -name "config" -exec cd {} \;
There is one match, ./my-applications/config, but after I try this it says:
find: `cd': No such file or directory
What am I doing wrong?
The command
cdis a shell built-in, not found in/binor/usr/bin.Of course, you can’t change directory to a file and your search doesn’t limit itself to directories. And the
cdcommand would only affect the executed command, not the parent shell that executes thefindcommand.Use:
Note that if your directory is not found, you’ll be back in your home directory when the command completes. (The
sed 1qensures you only pass one directory name tocd; the Korn shellcdtakes two values on the command and does something fairly sensible, but Bash ignores the extras.)