Table of Contents

What is pushd (Push Directory) in Bash?

About

Adds a directory to the top of the directory stack, or rotates the stack, making the new top of the stack the current working directory.

If the pushd command is successful, a dirs is performed as well.

Syntax

With no arguments

pushd 

With no arguments, exchanges the top two directories and returns 0, unless the directory stack is empty.

First Form

pushd [-n] [dir]

if supplied, have the following meanings:

pushd returns 0 unless the cd to dir fails.

Second Form

pushd [-n] [+n] [-n]

where:

pushd returns 0 unless the directory stack is empty, a non-existent directory stack element is specified, or the directory change to the specified new current directory fails.

Example

Go away and returns

# we are now in /
pushd /aDir/
# we are now in /aDir/
popd
# we are now back in the starting current directory /