Linux Command

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

  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.