What is pushd (Push Directory) in Bash?

Bash Liste Des Attaques Ovh

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:

  • -n: Rotates the stack so that the nth directory (counting from the right of the list shown by dirs, starting with zero) is at the top.
  • or ?? -n Suppresses the normal change of directory when adding directories to the stack, so that only the stack is manipulated.
  • dir Adds dir to the directory stack at the top, making it the new current working directory.

pushd returns 0 unless the cd to dir fails.

Second Form

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

where:

  • +n: Rotates the stack so that the nth directory (counting from the left of the list shown by dirs, starting with zero) is at the top.
  • -n: Rotates the stack so that the nth directory (counting from the right of the list shown by dirs, starting with zero) is at the top.
  • -n Suppresses the normal change of directory when adding directories to the stack, so that only the stack is manipulated.

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 /





Discover More
Bash Liste Des Attaques Ovh
Bash - Builtin Commands

builtin refers to: a builtin command. See or to the specific builtin command. See (useful when defining a function whose name is the same as a shell builtin) The builtin command execute the specified...
Bash Liste Des Attaques Ovh
Bash - Directory stack

The directory stack permits to navigate and come back in the directory tree. Directories are added to the list with the pushd command; See pushd The popd command removes entries from...



Share this page:
Follow us:
Task Runner