I wonder why nobody mentioned this.
There is a really useful use case for pushdpushd and popd commandspopd commands for working with several folders simultaneously.
Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Visit Stack ExchangeStack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
Explore Stack InternalI wonder why nobody mentioned this.
There is a really useful use case for pushdpushd and popd commandspopd commands for working with several folders simultaneously.
I wonder why nobody mentioned this.
There is a really useful use case for pushd and popd commands for working with several folders simultaneously.
There is a really useful use case for pushd and popd commands for working with several folders simultaneously.
I wonder why nobody mentioned this.
There is a really useful use case for pushd and popd commands for working with several folders simultaneously.
You can navigate the stack very easily, since it is enumerated. Meaning, you can have several working folders at your disposal during work.
See a simple example below.
First, let's create example folder structure.
user@vb:~$ mkdir navigate user@vb:~/navigate$ mkdir dir1 user@vb:~/navigate$ mkdir dir2 user@vb:~/navigate$ mkdir dir3 Then you can add all your folders to the stack:
user@vb:~/navigate$ pushd dir1/ ~/navigate/dir1 ~/navigate user@vb:~/navigate/dir1$ pushd ../dir2/ ~/navigate/dir2 ~/navigate/dir1 ~/navigate user@vb:~/navigate/dir2$ pushd ../dir3/ ~/navigate/dir3 ~/navigate/dir2 ~/navigate/dir1 ~/navigate You can look it up by:
user@vb:~/navigate/dir3$ dirs -v 0 ~/navigate/dir3 1 ~/navigate/dir2 2 ~/navigate/dir1 3 ~/navigate To navigate safely, you need to add the last (zero) folder twice, since it will be always rewritten:
user@vb:~/navigate/dir3$ pushd . user@vb:~/navigate/dir3$ dirs -v 0 ~/navigate/dir3 1 ~/navigate/dir3 2 ~/navigate/dir2 3 ~/navigate/dir1 4 ~/navigate Now, you can jump around through these folders and work with stack as with aliases for the folders. I guess the following part is self explanatory:
user@vb:~/navigate/dir3$ cd ~4 user@vb:~/navigate$ dirs -v 0 ~/navigate 1 ~/navigate/dir3 2 ~/navigate/dir2 3 ~/navigate/dir1 4 ~/navigate user@vb:~/navigate$ cd ~3 user@vb:~/navigate/dir1$ dirs -v 0 ~/navigate/dir1 1 ~/navigate/dir3 2 ~/navigate/dir2 3 ~/navigate/dir1 4 ~/navigate user@vb:~/navigate/dir1$ touch text.txt user@vb:~/navigate/dir1$ cp text.txt ~2 user@vb:~/navigate/dir1$ ls ~2 text.txt user@vb:~/navigate/dir1$ dirs -v 0 ~/navigate/dir1 1 ~/navigate/dir3 2 ~/navigate/dir2 3 ~/navigate/dir1 4 ~/navigate Additional tip is to create some alias for dirs -v.
For example:
# In ~/.bashrc alias dirs="dirs -v"