TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Linux terminal trick: Hack the CD command to remember where you've been

5 pointsby jhibbetsover 4 years ago

1 comment

freedombenover 4 years ago
This is a neat idea, but I don&#x27;t do it because most of the time I don&#x27;t want to have to traverse every previous dir. If you use `cd -` then you&#x27;ll go back to the previous dir anyway, which covers most cases. Beyond that, it&#x27;s just better to get in the habit of using pushd so that you can jump back to exactly where you want :-) It&#x27;s totally worth it.<p>One thing that annoys me is that popd consumes the top of the stack, which I something don&#x27;t want. I put this in my bashrc some years ago which basically executes a popd but doesn&#x27;t pop the stack:<p><pre><code> alias peekd=&#x27;cd &quot;$(dirs -l -p | sed -n &#x27;\&#x27;&#x27;2{p;q}&#x27;\&#x27;&#x27;)&quot;&#x27;</code></pre>