popd

Removes a directory from the directory stack.

Summary

popd [-n] [+N | -N]

The main purpose

Options

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

Parameters

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

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

return value

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

example

#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
[user2@pc ~]$ pushd -n ~/bin
~ ~/bin ~/Pictures ~/Desktop

# Remove a directory from the directory stack. Deleting the top directory will change the current working directory:
[user2@pc ~]$ popd -2
~ ~/Pictures ~/Desktop
[user2@pc ~]$ popd +1
~ ~/Desktop
[user2@pc ~]$ popd
~/Desktop
[user2@pc Desktop]$
# Remove a directory from the directory stack. Deleting the top directory does not change the current working directory:
[user2@pc ~]$ dirs
~
[user2@pc ~]$ pushd -n ~/Desktop
~ ~/Desktop
[user2@pc ~]$ popd -n
~
[user2@pc ~]$

Notice

Reference link