Learn how to populate a directory stack so you can more efficiently navigate around the Linux directories you use most.
Most Linux admins eventually wind up using the terminal window. Within that tool, you'll navigate through the directory hierarchy using the cd command. But on those days when you're constantly moving in and out of directories, having to type out those long paths can be a real efficiency killer.
What if there was a way to make this easier?
There is, thanks to the pushd command.
SEE: 10 things companies are keeping in their own data centers (TechRepublic download)
With pushd you can populate a directory stack and easily move between them. Say you'll be working within /etc/ /var/log/ /var/www/html /etc/apache2/sites-available and ~/ throughout the day. Why bother typing out those directories when you can make things easier?
Let me show you how.
Populate the pushd stack with the directories you want with the following commands (modify as needed):
pushd /etc pushd /var/log/ pushd /var/www/html pushd /etc/apache2/sites-available pushd ~/
At this point your stack is populated and each entry will have an associated number.
To find those numbers, issue the command:
With those numbers in hand, you can quickly switch to any of those directories with the command pushd +X, where X is the number associated with the directory you want to change into.
You can add as many directories as you like to the stack, and bouncing around from those directories is far easier now. Enjoy your new-found efficiency.
- Hiring kit: Database administrator (TechRepublic Premium)
- How to run multiple Linux commands from one line (TechRepublic)
- How to clone a drive from the Linux command line (TechRepublic)
- How to use the pipe in Linux commands (TechRepublic)
- How hyperscale data centers are reshaping all of IT (ZDNet)
- Best cloud services for small businesses (CNET)
- DevOps: More must-read coverage (TechRepublic on Flipboard)