Macos – In the Mac terminal, how to “find” a file and then quickly cd to the parent directory

findmacosterminal

I want to open terminal, find a file or folder, and quickly navigate to that folder or the parent directory of the file.

I can quickly get the path using

find ~ -name 'filename.txt' 

but I can't figure out how to copy that path result into the "cd" command

Is there a way to basically say "cd [path from find command]" or "open [path from find command]"

I'm just using the default terminal in OSX Mountain Lion

Best Answer

How about:

cd $(find -name "filename.txt" -type f -exec dirname {} \; | sed 1q)
Related Question