• Contact
  • Contact Us
  • Disclamer
  • Home 1
  • Home 2
  • Home 3
  • Privacy Policy
Wednesday, July 2, 2025
How VPS - How to use/setup VPS
  • Login
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
How VPS - How to use/setup VPS
No Result
View All Result
Home Operating System Linux

Use ‘pushd’ and ‘popd’ for Efficient Filesystem Navigation in Linux

How VPS by How VPS
November 2, 2018
in Linux, Operating System
0
0
SHARES
78
VIEWS
Share on FacebookShare on Twitter

Contents

  1. How pushd and popd Commands Work in Linux

Sometimes it can be painful to navigate the Linux file system with commands, especially for the newbies. Normally, we primarily use the cd (Change Directory) command for moving around the Linux file system.

In a previous article, we reviewed a simple yet helpful CLI utility for Linux called bd – for quickly moving back into a parent directory without typing cd ../../.. repeatedly.

This tutorial will explain a related set of commands: “pushd” and “popd” which are used for efficient navigation of the Linux directory structure. They exist in most shells such as bash, tcsh etc.

Suggested Read: Autojump – An Advanced ‘cd’ Command to Quickly Navigate Linux Filesystem

How pushd and popd Commands Work in Linux

pushd and popd work according to the “LIFO” (last in, first out) principle. In this principle, only two operations are allowed: push an item into the stack, and pop an item out of the stack.

pushd adds a directory to the top of the stack and popd removes a directory from the top of the stack.

To display directories in the directory stack (or history), we can use the dirs command as shown.

$ dirs
OR
$ dirs -v
Use ‘pushd’ and ‘popd’ for Efficient Filesystem Navigation in Linux

Dirs – Display Directories in Directory

pushd command – puts/adds directory paths onto a directory stack (history) and later allowing you to navigate back to any directory in history. While you add directories to the stack, it also echoes what’s existing in history (or “stack”).

The commands show how pushd works:

$ pushd  /var/www/html/
$ pushd ~/Documents/
$ pushd ~/Desktop/
$ pushd /var/log/
Use ‘pushd’ and ‘popd’ for Efficient Filesystem Navigation in Linux

pushd – Add Directories to Stack

From directory stack in the output above (directory index is in reverse order):

  • /var/log is the fifth [index 0] in the directory stack.
  • ~/Desktop/ is fourth [index 1].
  • ~/Documents/ is third [index 2].
  • /var/www/html/ is second [index 3] and
  • ~ is first [index 4].

Optionally, we can use the directory index in the form pushd +# or pushd -# to add directories to the stack. To move into ~/Documents, we would type:

$ pushd +2
Use ‘pushd’ and ‘popd’ for Efficient Filesystem Navigation in Linux

pushd – Directory Navigation with Number

Note after this, the stack content will change. So from the previous example, to move into /var/www/html, we would use:

$ pushd +1
Use ‘pushd’ and ‘popd’ for Efficient Filesystem Navigation in Linux

pushd – Navigate Directory with Number

popd command – removes a directory from the top of the stack or history. To list the directory stack, type:

$ popd

To remove a directory from the directory stack inded use popd +# or popd -#, in this case, we would type the command below to remove ~/Documents:

$ popd +1
Use ‘pushd’ and ‘popd’ for Efficient Filesystem Navigation in Linux

popd – Remove Directory from Stack

Also check out: Fasd – A Commandline Tool That Offers Quick Access to Files and Directories

In this tutorial we explained “pushd” and “popd” commands which are used for efficient navigation of the directory structure. Share your thoughts concerning this article via the feedback form below.

Source: tecmint.com

Tags: Linux Commandslinux guidelinux vps setup guide
Previous Post

bd – Quickly Go Back to a Parent Directory Instead of Typing “cd ../../..” Redundantly

Next Post

How to Fix Yum Error: Database Disk Image is Malformed

Next Post

How to Fix Yum Error: Database Disk Image is Malformed

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

No Result
View All Result

Recent Post

Install Imagemagick on CentOS
CentOS

Install Imagemagick on CentOS

by How VPS
June 28, 2023
0

This is how I installed Imagemagick on a vanilla CentOS server Start off by installing the prerequisites yum install php-pear...

Read more
how to Check phpinfo

How to Check phpinfo of Hosting or VPS?

June 28, 2023
Failed to download metadata for repo 'appstream' on Centos 8

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

February 25, 2022
How to Fix MySQL Error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed"?

How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”?

November 17, 2020
How to optimize Mysql or MariaDB

How to optimize Mysql or MariaDB

November 3, 2020

Recent News

  • Install Imagemagick on CentOS
  • How to Check phpinfo of Hosting or VPS?
  • How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

Category

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel
  • About
  • Advertise
  • Careers
  • Contact

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In