Stop running into dead ends with your cd command

Environment & Shell Customization (Aliases/Functions/.Bashrc)

Stop running into dead ends with your cd command

🧩 The Challenge

You know that feeling when you’re jumping between deep directory structures and realize you’ve completely lost track of where you are? I’ve spent way too much time hitting up arrow just to see the path I was in three minutes ago.

💡 The Fix

Instead of dealing with the default behavior, just make the shell keep a trackable stack of your recent directory history. It turns basic navigation into a stack-based workflow that actually makes sense.

pushd () { builtin pushd "$@" > /dev/null; dirs; }
popd () { builtin popd "$@" > /dev/null; dirs; }
alias cd='pushd'

⚙️ Why It Works

By overriding cd to trigger pushd, you force the shell to push every location onto a stack and display the full list every time you move. It makes it impossible to forget where you’ve been because the list is staring you in the face after every single move.

🚀 Pro-Tip: Use “dirs -v” if the list gets too long and you just need to see the index numbers to jump back.

Linux Tips & Tricks | © ngelinux.com | 9/1/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted