Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use pushd and popd commands in linux system

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to use pushd and popd commands in the linux system. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

You can easily switch between multiple directories using the pushd and popd commands in linux's shell. Efficiency can be greatly improved through the use of pushd and popd.

How pushd and popd commands work in Linux system

The pushd and popd commands work according to the 'LIFO' (last in, first out) principle. Under this principle, only two operations are allowed: push a directory onto the stack and pop a directory off the stack.

The pushd command adds a directory to the top of the stack, while the popd command removes a directory from the top of the stack.

To display the directories in the directory stack (or history), we can use the dirs command shown below:

$dirs or $dirs-v

Dirs- displays directories located in the directory stack

Pushd command: add / put a directory path to the directory stack (history), after which you can browse any directory located in the directory stack (history). When you put a new directory on the stack, all the directories currently on the stack are printed.

The following commands show how this command works:

$pushd / var/www/html/$ pushd ~ / Documents/$ pushd ~ / Desktop/$ pushd / var/log/

Pushd- adds a new directory to the stack

According to the directory stack output above (catalog indexes are arranged in reverse order):

/ var/log is the fifth directory in the directory stack, index 0~/Desktop/ is the fourth, index 1~/Document/ is the third, index 2/var/www/html is the second, index 3 ~ is the first, index 4

In addition, we can also use the form of directory index pushd + # or pushd-# to add directory stacks. To enter the directory ~ / Documents, we can type:

$pushd + 2

Pushd- browses the directory digitally

Notice that after the previous step, the contents of the stack have changed. So, to enter the directory / var/www/html from the above example, we should use the following command:

$pushd + 1

Pushd- browses the directory digitally

Popd command-removes a directory from the top of the stack or history. To list all the directories in the directory stack, simply enter:

$popd

To remove a directory from the directory stack, we can use the popd + # or popd-# command, at which point we need to type the following command to remove the directory ~ / Documents:

$popd + 1

Popd- removes directories from the stack

This is the end of this article on "how to use pushd and popd commands in the linux system". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report