Bash Directory Manipulation Built-in Commands

From NovaOrdis Knowledge Base
Revision as of 02:02, 19 January 2022 by Ovidiu (talk | contribs) (→‎pushd)
Jump to navigation Jump to search

Internal

Overview

pushd and popd are bash built commands.

Concepts

Directory Stack

DIRSTACK Environment Variable

DIRSTACK is an array variable that contains the current contents of the directory stack. Directories appear in the stack in the order they are displayed by the dirs builtin. Assigning to members of this array variable may be used to modify directories already in the stack, but the pushd and popd builtins must be used to add and remove directories. Assignment to this variable will not change the current directory. If DIRSTACK is unset, it loses its special properties, even if it is subsequently reset.

Commands

dirs

pushd

Change the current directory to the given directory, while saving the current working directory on the directory stack. Report the new and old directory at stdout.

To get rid of the stdout, direct it to /dev/null.

popd