Linux Command

pushd

Adds the directory to the top of the directory stack.

Summary

pushd [-n] [+N | -N | dir]

The main purpose

Options

-n suppresses changes to the current working directory caused by adding directories.

Parameters

+N (optional): In the list displayed by executing the dirs command without parameters, the Nth directory from the left will be the top of the stack, and the directory in front of it will be moved to the bottom. (counting from 0)

-N (optional): In the list displayed by executing the dirs command without parameters, the Nth directory from the right will be the top of the stack, and the directory in front of it will be moved to the bottom. (counting from 0)

dir (optional): The directory to push.

return value

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

example

# Add a directory to the stack, changing the current working directory.
[user2@pc ~]$ dirs
~
[user2@pc ~]$ pushd ~/Desktop
~/Desktop ~
[user2@pc Desktop]$
#Add a directory to the stack, leaving the current working directory unchanged.
[user2@pc ~]$ dirs
~
[user2@pc ~]$ pushd -n ~/Desktop
~ ~/Desktop
[user2@pc ~]$ pushd -n ~/Pictures
~ ~/Pictures ~/Desktop

# Adjust the order.
[user2@pc ~]$ pushd +1
~/Pictures ~/Desktop ~
[user2@pc ~]$ pushd -1
~/Desktop ~ ~/Pictures
[user2@pc ~]$ pushd
~ ~/Desktop ~/Pictures

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.

Reference link

Keep reading

You may need these next

Related picks, plus your reading history and saved articles.