pushd push a directory into the directory stack, and change the working directory. I guess that is all we need.

But besides, why does pushd always output the stack to stdout? I think that is unnecessary and add clutter to the screen, or I miss its point. Thanks.

closed as primarily opinion-based by muru, mosvy, JigglyNaga, RalfFriedl, Jeff Schaller Nov 8 '18 at 20:57

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    alias pushd='pushd >/dev/null' – mosvy Nov 8 '18 at 15:45

pushd and popd are primarily providing a convenient way to navigate directories interactively. In scripts, cd is more often used.

As an interactive tool, pushd gives the user feedback about the current state of the directory stack whenever a new directory is successfully pushed onto it. The cd command is sometimes wrapped in a shell function (for interactive use only) that in the same way outputs the new directory whenever the current working directory is changed. The r alias in ksh shells, which repeats the most recently given command, also gives the user feedback in the form of echoing the actual command that is being executed.

All these small pieces of feedback are there to help the user navigate and just to generally ensure that they are doing what they think they're doing when working at an interactive shell prompt.


It doesn't always do so, only if the command succeeds. From the manpage:

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

We can't read the mind of the original programmer but we can imagine it's to make sure the user is notified of the updated content of the stack.

Not the answer you're looking for? Browse other questions tagged or ask your own question.