Skip to content

dirs MacOS Command Guide

The MacOS dirs command allows users to navigate through directories and manipulate folder stacks efficiently. By managing directory locations as a stack, users can easily switch between different directories and access previously visited folders with ease. The dirs command enables users to push and pop directories onto the stack, list the stack, or navigate to a specific directory within the stack. This command can be particularly useful for users who frequently work with multiple directories and need to switch between them quickly and effectively.

Terminal window
dirs [-clpv]
OptionDescription
-cClear the directory stack.
-lPrint the directory stack with one entry per line.
-pPrint the directory stack with one entry per line, including indexes.
-vDisplay the directory stack index in front of each entry.

There are no parameters for the dirs command.

Terminal window
dirs

Display the list of directories in the directory stack.

Terminal window
cd -

Change to the previous directory in the directory stack.

Terminal window
cd +2

Change to the directory at position 2 in the directory stack.

Terminal window
pushd /path/to/directory

Push a directory onto the directory stack and change to it.

Terminal window
popd +1

Remove the directory at position 1 from the directory stack.

Terminal window
dirs -c

Clear the directory stack.

Terminal window
dirs -p

Display the directory stack contents as commands that can be copied and pasted.

To use the dirs command in MacOS, execute the following command:

Terminal window
dirs

How can I clear the directory stack in MacOS?

Section titled “How can I clear the directory stack in MacOS?”

To clear the directory stack in MacOS, you can use the following command:

Terminal window
dirs -c

How do I display the directory stack with line numbers in MacOS?

Section titled “How do I display the directory stack with line numbers in MacOS?”

To display the directory stack with line numbers in MacOS, execute the following command:

Terminal window
dirs -v

How can I navigate to a specific directory in the stack in MacOS?

Section titled “How can I navigate to a specific directory in the stack in MacOS?”

To navigate to a specific directory in the stack in MacOS, you can use the following command with the directory number:

Terminal window
cd $(dirs +<number>)

How do I add a specific directory to the stack in MacOS?

Section titled “How do I add a specific directory to the stack in MacOS?”

To add a specific directory to the stack in MacOS, you can use the pushd command followed by the directory path:

Terminal window
pushd /path/to/directory

How do I remove a specific directory from the stack in MacOS?

Section titled “How do I remove a specific directory from the stack in MacOS?”

To remove a specific directory from the stack in MacOS, you can use the popd command followed by the directory number or path:

Terminal window
popd +<number>
  • Save and quickly switch between frequently accessed directories
  • Create a stack of directories to navigate back and forth within a session
  • Simplify the navigation process in the terminal
  • Improve efficiency when working with multiple directories at once