Site icon New Generation Enterprise Linux

Stop cd from leaving you lost in deep directory trees

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

Stop cd from leaving you lost in deep directory trees

🧩 The Challenge

You ever find yourself typing cd .. a dozen times just to move back to the root of a project, only to realize you went too far? It’s a massive waste of keystrokes when you’re jumping between submodules or buried deep in a build folder.

💡 The Fix

Throw a quick shell function into your rc file that lets you jump back by index number instead of blindly hammering dots. It saves your sanity when you’re nested five levels deep.

up() { local c=$1; [[ -z "$c" ]] && c=1; for i in $(seq 1 $c); do cd ..; done; }

⚙️ Why It Works

The loop iterates through the integer you provide and chains the cd command together, effectively teleporting you up the tree based on the number of levels you choose. It’s simple, it’s reliable, and it avoids the repetitive strain of hitting backspace or dots.

🚀 Pro-Tip: Alias this to something like ‘back’ if you hate typing ‘up’ every time.

Linux Tips & Tricks | © ngelinux.com | 7/24/2026

0 0 votes
Article Rating
Exit mobile version