Master Shortcuts for Long Linux Paths: cd, pushd, popd & Alias Tricks
Learn how to efficiently navigate deep Linux directories by using shortcuts such as cd -, the pushd/popd stack commands, and custom alias definitions, with step‑by‑step examples that show how to set up and persist these shortcuts in your bash environment.
How to Deal with Very Long Linux Paths: Handy Tips
When using cd in Linux, navigating deep directories can be cumbersome. The cd - command quickly switches between the current and previous directory because it is equivalent to cd $OLDPWD, where $OLDPWD stores the last path.
If you need to switch among more than two directories, the pushd and popd commands, together with dirs, provide a stack‑based solution. pushd pushes the current directory onto a stack and moves to the specified one, e.g. pushd /path/to/target. You can view the stack with dirs -v, which lists directories with numeric indices.
Using pushd +N jumps to the directory at position N in the stack. popd removes entries from the stack; popd +N pops the directory at index N, while popd without arguments returns to $OLDPWD.
An alternative shortcut is to create an alias. The syntax is alias name='command'. For example, defining alias cdpath='cd /very/long/path' lets you type cdpath to jump directly to that directory.
To make the alias permanent, add it to a script (e.g., alias_cd.sh) and source that script from your ~/.bashrc (or the system /etc/bashrc) with a line such as source /etc/alias_cd.sh. After reloading the shell, the alias works in every session.
These techniques— cd -, pushd/popd, and custom aliases—significantly speed up directory navigation on Linux.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
