---
title: 'Quick Tip: Jumping to the Finder location in Terminal'
date: 2013-02-09 05:00
slug: quick-tip-jumping-to-the-finder-location-in-terminal
categories:
- Code
tags:
- macos
- terminal
---

![Terminal icon](https://brettterpstra.com/uploads/2013/02/terminalicon.png)

I'd been meaning to write a script to do this for a while, and a [post by Dr. Drang](http://www.leancrew.com/all-this/2013/01/textexpander-posix-paths-and-forgetfulness/) inspired me to whip it up. Dr. Drang's is a TextExpander snippet (which also works fine in shell if you use "quoted form of" to be safe). This method is just a tad more convenient for Terminal usage. It's a two-line bash function for quickly `cd`-ing to the location of the front Finder window with a simple command (`cdf`).

There are a few utilities to do this, like [ShellTo](https://itunes.apple.com/us/app/shellto/id418075847?mt=12&partnerId=30&siteID=vRL5rYo4h5A) and [GoToShell](https://itunes.apple.com/us/app/go2shell/id445770608?mt=12&partnerId=30&siteID=vRL5rYo4h5A), but why run an extra process when it's this easy? Just throw this in `~/.bash_profile`:

	# cd to the path of the front Finder window
	cdf() {
		target=`osascript -e 'tell application "Finder" to if (count of Finder windows) > 0 then get POSIX path of (target of front Finder window as text)'`
		if [ "$target" != "" ]; then
			cd "$target"; pwd
		else
			echo 'No Finder window found' >&2
		fi
	}

[*Updated based on suggestions from Rob Trew to fail gracefully when no Finder window is open*]

You can also create an alias to do the reverse:

	alias f='open -a Finder ./'

Run `source ~/.bash_profile` and type `cdf` to change your working directory to match your Finder location. Type `f` to open a Finder window to your current location in the shell.

Combine the speed and Unix power of the shell with the convenience and added functionality of Finder!

---

Brett is a writer and developer living in Minnesota, USA. You can follow him as ttscoff. This content is supported by readers like you. [More about Brett](https://brettterpstra.com/contact.md), including social links.

Copyright © 2026 Brett Terpstra. All rights reserved.
