Find query

when i search for a file using find i want to be able to cd to the directory of the file

simple find i'm using is
find . -name <filename> the output is the full path to the file, i want to use the output to cd into the directory... I need to add this into a script

Any ideas pls

To get the name of the directory you can do something like:

file=$(find . -name <filename>)
dir=${file%/*}
1 Like

Worked a treat many thanks