In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use pushd and popd to switch directories efficiently under Linux, which has a certain reference value, and interested friends can refer to it. I hope you can learn a lot after reading this article.
Pushd and popd operate on a directory stack, while dirs displays the contents of the directory stack. The directory stack is a stack structure that holds the directory, and the top of the stack structure always stores the current directory.
1. Pushd, popd and dirs1.1 dirs
There are two parameters commonly used in dirs:
Option meaning-p displays one record per line-v displays one record per row, while showing the record in the stack index-c empties the catalog stack
The following does not show any operation on the directory stack, let's take a look at the contents of the current directory stack:
$pwd/home/lfqy$ dirs-v0 ~ $cd / $dirs-v0 / $dirs-c $dirs-v0 / $
As you can see, there is only one directory in the directory stack (at the top of the stack, of course), which is the current directory. When you switch directories, the directories in the stack also change. The-c option clears all directories in the directory stack except the current directory, and since the directory stack in the above example contains only the current directory, there is no change.
1.2 pushd
After each execution of the pushd command, a dirs command is executed by default to display the contents of the directory stack. The main uses of pushd are as follows:
Pushd directory
If pushd is used directly with a directory, it changes to that directory and places the directory at the top of the directory stack. Always keep in mind that the top of the directory stack always holds the current directory. If the current directory changes, the top element of the directory stack must also change; conversely, if the top element of the stack changes, the current directory must also change.) Here is an example:
$pwd/home/lfqy$ pushd / / ~ $dirs-v0 / 1 ~ $pushd ~ / Music/~/Music / ~ $dirs-v0 ~ / Music1 / 2 ~ $
In this way, it is not difficult to see that while switching directories with pushd, the historical directories are also saved in the form of stack structure.
Pushd takes no parameters.
The effect of pushd execution without any parameters is to swap the two directories at the top of the directory stack. As mentioned earlier, one of the top stack directories and the current directory has changed, and so has the other. In this way, in fact, the cd-function is implemented. Here is an example (this example follows the implementation site above):
$dirs-v0 ~ / Music1 / 2 ~ $pushd/ ~ / Music ~ $dirs-v0 / 1 ~ / Music2 ~ $pushd~/Music / ~ $dirs-v0 ~ / Music1 / 2 ~ $
Pushd + n
At this point, you might wonder what if you want to switch to any directory in the directory stack? Pushd + n does exactly this: pushd + n changes to the nth directory in the directory stack (where n is the index shown by the dirs-v command) and pushes the directory to the top of the stack in a stack loop. Here is an example (following the execution site above). Pay attention to the changes in the contents of the stack brought about by the way the stack loop is used:
$dirs-v0 ~ / Music1 / 2 ~ $pushd + 2 ~ ~ / Music / $dirs-v0 ~ 1 popd / Music2 / $pushd + 1~/Music / ~ $dirs-v0 ~ / Music1 / 2 ~ $1.30 popd
After each execution of the popd command, a dirs command is executed by default to display the contents of the directory stack. The main uses of popd are as follows:
Popd has no parameters
The effect of popd execution without any parameters is to unstack the top element in the directory stack. At this point, the elements at the top of the stack change, and naturally the current directory will be switched accordingly (following the execution site above). Here is an example:
$dirs-v0 ~ / Music1 / 2 ~ $popd/ ~ $dirs-v0 / 1 ~ $popd~$ dirs-v0 ~ $
Popd + n
Delete the nth element in the directory stack (n here is the directory index shown by the command dirs-v). Here is an example:
$dirs-v0 ~ / Music1 / 2 ~ $popd + 2~/Music / $
It can be found here that if the operation on the directory stack does not cause a change in the elements at the top of the stack, it will not lead to the switching of the current directory.
2. + n and-n of pushd and popd
We use + n as the parameter above. In fact, the-n parameter is sometimes used when using pushd and popd. The difference between the two is as follows: + n means to count from the top of the stack to the bottom of the stack, starting from 0;-n means the opposite, counting from the bottom of the stack to the top of the stack, starting at 0. This is a bit of a mouthful. In fact, the explanation from the output of the default dirs command (without any arguments) is best understood: + n refers to counting from left to right, and-n refers to counting from right to left, starting with 0.
Thank you for reading this article carefully. I hope the article "how to use pushd and popd to switch directories efficiently under Linux" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.