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.
Articles Related
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 /