Published on

popd command-delete records from the shell directory stack



1 min read

Used to delete records from the Shell directory stack. If no option is added, the popd command deletes the record at the top of the Shell directory stack first, and then switches the current directory to the top directory of the new Shell directory stack.

Syntax: popd [parameter]

Command parameters
-nDelete the nth directory from the right (n starts counting from 0)
+nDelete the nth directory from the left (n starts counting from 0)

Display the contents of the Shell directory stack, one per line:

[root@linuxstar ~]# dirs -v
0 /sbin
1 /etc
2 /var/log

Remove /sbin from the shell directory stack:

[root@linuxstar ~]# popd
/etc /var/log

Display the current working directory:

[root@linuxstar ~]# pwd

Delete the top directory from the directory stack:

[root@linuxstar ~]# popd

Delete the second directory from the right from the directory stack:

[root@linuxstar ~]# popd -2