Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find -exec cd in linux / unix

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?

like image 882
cwd Avatar asked Jun 13 '11 21:06

cwd


People also ask

How do I find my CD files?

Open System Information. In the System Information window, click the + symbol next to Components. If you see "CD-ROM," click it once to display the CD-ROM in the left window. Otherwise, click "+" next to "Multimedia" and then click "CD-ROM" to see the CD-ROM information in the left window.

How do I know if my CD is mounted Linux?

Usually on Linux, when an optical disc is mounted, the eject button is disabled. To determine whether anything is mounted in the optical drive, you can check the contents of /etc/mtab and look for either the mount point (e. g. /mnt/cdrom ) or the device for the optical drive (e. g. /dev/cdrom ).


1 Answers

The command cd is a shell built-in, not found in /bin or /usr/bin.

Of course, you can't change directory to a file and your search doesn't limit itself to directories. And the cd command would only affect the executed command, not the parent shell that executes the find command.

Use:

cd $(find . -name config -type d | sed 1q)

Note that if your directory is not found, you'll be back in your home directory when the command completes. (The sed 1q ensures you only pass one directory name to cd; the Korn shell cd takes two values on the command and does something fairly sensible, but Bash ignores the extras.)

like image 73
Jonathan Leffler Avatar answered Nov 01 '22 20:11

Jonathan Leffler