Innovate | Connect | Transform
ContactService statusUSD $

GICT knowledge base

pushd, popd & zoxide: The Better Way to Move in Linux

Published

Linux

If you use Linux, you probably spend a lot of time moving between folders. Most people use the cd command to change directories. But there are better and faster ways to do this.

This guide will show you three simple tools that make moving around much easier. These tools are pushd, popd, and zoxide. They help you save time and avoid typing long folder paths over and over.

Why the cd Command is Not Perfect

The cd command works okay for basic tasks. But it has some problems:

  • You have to type the full path every time
  • Going back to where you were before is annoying
  • You cannot easily switch between many folders
  • It does not remember the folders you use often

When you work with lots of folders, these problems waste your time.

What are pushd and popd?

Think of pushd and popd like bookmarks for your folders. They help you save your location and come back to it later.

Using pushd

The pushd command does two things at once. It saves where you are right now and then moves you to a new folder.

pushd /var/www/html

This takes you to the folder called /var/www/html. But it also remembers where you started.

Using popd

The popd command brings you back to where you were before.

popd

That is it. You go back to your last folder with one simple command.

Simple Example

Imagine you are working on a website project:

cd ~/projects/website
pushd /etc/nginx/sites-available
# Now you edit some settings
popd
# You are back in ~/projects/website

You can save many folders in a row:

pushd /var/log
pushd /etc/apache2
pushd ~/downloads

Now when you type popd, you go back through each folder in reverse order.

How the Directory Stack Works

See Your Saved Folders

To see all the folders you saved, type:

dirs -v

This shows you a list with numbers next to each folder.

Jump to Any Saved Folder

You can go to any folder in your list by using its number:

pushd +2

This takes you to the third folder in your list.

Clear All Saved Folders

To delete everything from your list:

dirs -c

What is zoxide?

While pushd and popd are helpful, zoxide is even smarter. It is like a cd command that remembers what you do and learns from it.

What Makes zoxide Special

  • It remembers the folders you visit most often.
  • You can go to folders by typing just a few letters.
  • You do not need to type full paths anymore.
  • It works all the time, even when you close and open the terminal.
  • It is much faster than the old way of doing things.

How to Install zoxide

On Ubuntu or Debian

sudo apt install zoxide

On CentOS or RHEL

dnf install zoxide

On Arch Linux

pacman -S zoxide

Making zoxide Work

After you install it, open your .bashrc file and add this line:

eval "$(zoxide init bash)"

If you use zsh instead of bash:

eval "$(zoxide init zsh)"

Then restart your terminal or type:

source ~/.bashrc

How to Use zoxide

Basic Use

Instead of typing cd, you type z:

z documents

This takes you to your documents folder. You do not need to type the full path.

Smart Jumping

zoxide learns which folders you use most. If you often go to /var/www/html/mysite, you can just type:

z mysite

zoxide will take you there right away.

Choosing from Options

If many folders match what you typed, use zi to pick one:

zi proj

This shows all matching folders and lets you choose which one you want.

Going Up Folders

Type z .. to go up one folder level. Or type z ../.. to go up two levels.

Comparing All Three Methods

Regular cd Command

  • Good Things:
    • Works on every Linux system.
    • Easy to understand.
    • Already there, no need to install.
  • Bad Things:
    • You must type long paths.
    • No shortcuts or memory.
    • Takes more time.

pushd and popd

  • Good Things:
    • Already installed on most systems.
    • Great when you switch between two folders.
    • Keeps a list of where you have been.
  • Bad Things:
    • You have to manage the list yourself.
    • Only goes forward and backward.
    • The list gets messy if you save too many folders.

zoxide

  • Good Things:
    • Learns what you do automatically.
    • Very fast to use.
    • Works with short folder names.
    • Remembers which folders you use most.
  • Bad Things:
    • You need to install it first.
    • Takes a little time to learn.
    • Needs time to remember your folders.

Real Examples

For People Who Build Websites

When you work on different projects:

z website
# Make changes to files
z nginx
# Change server settings
z logs
# Look at error messages
z website
# Go back to your project

For Server Managers

Moving between different server folders:

z apache
z mysql
z backup
z scripts

You do not have to type /etc/apache2/sites-available every single time.

For IT Teams

Going between different locations:

pushd /var/www/production
# Put new code on the live server
pushd /var/www/staging
# Test on the test server
popd
# Go back to production
popd
# Return to where you started

Common Problems

zoxide Cannot Find Your Folder

Problem: You made a new folder but z cannot find it.
Solution: Go there once with cd first. Then zoxide will remember it.

cd /path/to/new/folder
z newfolder

Too Many Saved Folders

Problem: Your pushd list has too many folders.
Solution: Clear it with dirs -c or use popd to remove old ones.

zoxide Goes to Wrong Folder

Problem: zoxide takes you to a folder you did not want.
Solution: Use the full path once to teach it the right place. Or use zi to pick from a list.

Extra zoxide Features

    • Make Folders More Important:
      Add important folders:
zoxide add /important/project
    • See All Folders:
      Look at every folder zoxide knows:
zoxide query --list
    • Skip Some Folders:
      Stop zoxide from tracking certain folders. Add this to .zshrc:
export _ZO_EXCLUDE_DIRS="/tmp:/var"

How Much Time You Save

These tools really do save time:

  • pushd and popd: Save about 30 to 40 percent of time when going back and forth.
  • zoxide: Can reduce typing by 70 to 80 percent for folders you use a lot.
  • Using all of them: Can save you 10 to 15 minutes every day.

Final Thoughts

Moving around Linux folders does not need to be hard. The cd command is basic, but pushd and popd let you jump back and forth quickly. And zoxide is smart enough to learn what you do and help you move faster.

Try installing zoxide on your computer today. Use pushd and popd when you need to switch folders temporarily. Your work will get much easier and faster.

Millions of people already use these tools. They are safe, fast, and trusted by people who work with servers and websites every day. Try them out and see how much time you save.

Related guides

Account services are unavailable until the production backend is configured.