{"id":36221,"date":"2026-07-05T09:04:47","date_gmt":"2026-07-05T16:04:47","guid":{"rendered":"https:\/\/www.podfeet.com\/blog\/?p=36221"},"modified":"2026-07-05T09:04:47","modified_gmt":"2026-07-05T16:04:47","slug":"cdpath","status":"publish","type":"post","link":"https:\/\/www.podfeet.com\/blog\/2026\/07\/cdpath\/","title":{"rendered":"Bruce from Tennessee Explains CDPATH"},"content":{"rendered":"<p>Hi.  This is Bruce from East Tennessee, aka UseTheData, with a quick terminal tip about something called <code>CDPATH<\/code>.<\/p>\n<p>The problem to be solved is that I work in the terminal quite a bit, and I want to quickly get into my project folders, which are largely in Dropbox.  In the terminal, we use the <code>cd<\/code> command to do this, as Bart and Allison discussed way back in <a href=\"https:\/\/ttt.bartificer.net\/book.html#ttt04\">Taming the Terminal episode 4<\/a>.  However, Apple changed a lot of things about where cloud storage files are located.  My Dropbox folder used to be at the root of my user folder (i.e. <code>~\/Dropbox<\/code>), but it&#8217;s now at <code>~\/Library\/CloudStorage\/Dropbox<\/code>.  Instead of getting to my current projects with <code>cd ~\/Dropbox\/Current-Projects<\/code>, I would have to type <code>cd ~\/Library\/CloudStorage\/Dropbox\/Current-Projects<\/code>, which is a lot longer.<\/p>\n<p>I say &#8220;would have to type&#8221; because one of the ways to solve this problem is something called <code>CDPATH<\/code>.  <code>CDPATH<\/code> is a terminal environment variable, similar to the <code>PATH<\/code> variable that Bart and Allison described in <a href=\"https:\/\/ttt.bartificer.net\/book.html#ttt13\">Taming the Terminal episode 13<\/a>, except that <code>CDPATH<\/code> works with the <code>cd<\/code> command, rather than the way <code>PATH<\/code> is used to make getting to executable files easier.<\/p>\n<p>I&#8217;ll go into the details in a minute, but the result is that I can now type <code>cd Current-Projects<\/code> and land in the folder for all of my current projects, regardless of where I am in the file system.  I can also go directly to the folder for any individual current project.  For example, I have a project to track the maintenance work I do around the house.  I can now type <code>cd Maintenance,<\/code> and that will land me in the folder for that project, regardless of where I am in the file system.<\/p>\n<p>How do I do this?<\/p>\n<p>The answer is a line in my <code>.zshrc<\/code> that sets the <code>CDPATH<\/code> variable.  For me, that line is<\/p>\n<pre><code class=\"language-zsh\">export CDPATH=\".:$HOME\/Library\/CloudStorage\/Dropbox:$HOME\/Library\/CloudStorage\/Dropbox\/Current-Projects:$HOME\/Documents\"\n<\/code><\/pre>\n<p>The result of setting this variable is that when I type <code>cd &lt;folder-name&gt;<\/code>, the <code>cd<\/code> command will first look in the current folder &#8212; that&#8217;s the dot at the start of the <code>CDPATH<\/code> variable.  It will then look for that folder at the root of my Dropbox.  It will then look for that folder in my Current-Projects folder.  And lastly, it will look for that folder in my Documents folder.<\/p>\n<p>But wait, it gets better.<\/p>\n<p>In the default macOS configuration with <code>zsh<\/code>, I have to type the full folder name, such as &#8220;Current-Projects&#8221; to get there.  But just the first three letters C-u-r are unique.  What if I could just type <code>cd Cur<\/code> then hit the tab key and land in that <code>Current-Projects<\/code> folder?<\/p>\n<p>It turns out that I can, though it involves a pretty arcane incantation.<\/p>\n<p>The answer is to add these two lines to your <code>.zshrc<\/code> file:<\/p>\n<pre><code class=\"language-zsh\">autoload -Uz compinit\ncompinit\n<\/code><\/pre>\n<p>I&#8217;m not going to go into why this works.  The Valuable Dev&#8217;s <a href=\"https:\/\/thevaluable.dev\/zsh-completion-guide-examples\/\">article on zsh completion<\/a> goes into a lot of details.  I have been through this, and I&#8217;m comfortable that I understand why this enables the tab completion for folder names with the <code>cd<\/code> command.  But it would be a definite propeller head episode of Taming the Terminal to explain it.  For what it&#8217;s worth, I didn&#8217;t have to enable <code>compinit<\/code> on my Ubuntu system.  Tab completion with <code>cd<\/code> just worked.  Which is what led me to go hunting for a way to make it work on my Mac.<\/p>\n<p>This is definitely a bit on the nerdy side, but it&#8217;s a very useful tool for moving around the file system if you work in the terminal.<\/p>\n<p>Peace, and may you find beauty in the world around you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi. This is Bruce from East Tennessee, aka UseTheData, with a quick terminal tip about something called CDPATH. The problem to be solved is that I work in the terminal quite a bit, and I want to quickly get into my project folders, which are largely in Dropbox. In the terminal, we use the cd [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":36224,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[147],"tags":[8336,4866,603,229],"class_list":["post-36221","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog-posts","tag-cdpath","tag-path-bar","tag-taming-the-terminal","tag-terminal"],"jetpack_featured_media_url":"https:\/\/www.podfeet.com\/blog\/wp-content\/uploads\/2026\/07\/FINAL-Taming-the-Terminal-book-cover-art-V2-1040x520-1.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.podfeet.com\/blog\/wp-json\/wp\/v2\/posts\/36221","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.podfeet.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.podfeet.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.podfeet.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.podfeet.com\/blog\/wp-json\/wp\/v2\/comments?post=36221"}],"version-history":[{"count":1,"href":"https:\/\/www.podfeet.com\/blog\/wp-json\/wp\/v2\/posts\/36221\/revisions"}],"predecessor-version":[{"id":36222,"href":"https:\/\/www.podfeet.com\/blog\/wp-json\/wp\/v2\/posts\/36221\/revisions\/36222"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.podfeet.com\/blog\/wp-json\/wp\/v2\/media\/36224"}],"wp:attachment":[{"href":"https:\/\/www.podfeet.com\/blog\/wp-json\/wp\/v2\/media?parent=36221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.podfeet.com\/blog\/wp-json\/wp\/v2\/categories?post=36221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.podfeet.com\/blog\/wp-json\/wp\/v2\/tags?post=36221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}