TrumanWong

dirs

Display directory stack.

grammar

dirs [-clpv] [+N] [-N]

The main purpose

  • Show directory stack.
  • Clear the directory stack.

Options

-c Clears the directory stack.
-l Directories starting with ~ in the stack are expanded when displayed.
-p displays each directory in the directory stack on a line basis.
-v displays each directory in the directory stack by line and adds the position number in the stack before each line.

Parameters

+N (optional): In the list displayed by executing the dirs command without parameters, the Nth directory from the left will be displayed. (counting from 0)

-N (optional): In the list displayed by executing the dirs command without parameters, the Nth directory from the right will be displayed. (counting from 0)

return value

Returns successful unless an illegal option is provided or an execution error occurs.

example

# Add directories to the stack.
[user2@pc ~]$ dirs
~
[user2@pc ~]$ pushd -n ~/Desktop
~ ~/Desktop
[user2@pc ~]$ pushd -n ~/Pictures
~ ~/Pictures ~/Desktop
[user2@pc ~]$ pushd -n ~/bin
~ ~/bin ~/Pictures ~/Desktop

# Examples of options and parameters:
[user2@pc ~]$ dirs -l
/home/user2 /home/user2/bin /home/user2/Pictures /home/user2/Desktop
[user2@pc ~]$ dirs -p
~
~/bin
~/Pictures
~/Desktop
[user2@pc ~]$ dirs -v
  0 ~
  1 ~/bin
  2 ~/Pictures
  3 ~/Desktop
[user2@pc ~]$ dirs +2
~/Pictures
[user2@pc ~]$ dirs -2
~/bin
[user2@pc ~]$ dirs -c
[user2@pc ~]$ dirs
~

Notice

  1. The directory stack commands of bash include dirs popd pushd.
  2. The current directory is always at the top of the directory stack.
  3. This command is a built-in bash command. For related help information, please see the help command.