Play With Directory Stack
Sometimes we work with long paths in directories and it is hard to remember all of them. What about popping them when we need them?
There is a solution to this, it is called directory stack. As the name suggests, a directory stack is a stack in which we can push and pop directories when we need them.
The directory stack is based on the principle of LIFO. What is LIFO? LIFO means last in, first out. The last directory pushed in the stack will be the first directory which will go out of the stack. To play with the stack directory you need to learn and use the following commands:
dirs: Display the directory stack and the current directory
pushd: Push the directory into the stack
popd: Pop the directory out of the stack and change directory to it
It is time to push some directories into the stack. But, let me create some directories as shown below.
How to use dirs command? Just type dirs in the terminal like shown in Figure 2. As you see from Figure 2 my directory stack is empty and dirs command outputs the name of the current directory.
Now we cd to the directory we want to push to the stack and use the pushd command followed by a dot like shown in Figure 3. First I cd to test1, then I use pushd. like shown in Figure 3. After the pushd . is executed, the current directory goes into stack and stack automatically gives us information about items that are inside it.
There is only one directory in the stack, the first one is the current directory. We use the popd command to pop the directory out of the stack like shown in Figure 4.
To prove that the first item in the stack is the current directory, use the dirs command or use popd again. If i use popd again, I will get a message that the directory stack is empty like shown in Figure 5.
But how does stack directory help you to navigate through directories? The popd command does this for us. After it pops out the directory it changes to that directory. It does the magic for us!
Like us on Facebook
This week Top Posts
- Top Things To Do After Installing Ubuntu 13.10 'Saucy Salamander' : Ubuntu 13.10 Saucy Salamander will be released on coming October 17th with many new salient featur...0 comments |
- How To Install Netflix In Ubuntu : Hi unixmen readers! How are you? In this article we will teach you how to install the desktop vers...2 comments |
- How To Configure Linux Clients To Authenticate Using OpenLDAP : This is the continuation of our previous tutorial. In our previous tutorial we learned how to instal...2 comments |
- How To Upgrade From Ubuntu 13.04 Raring To Ubuntu 13.10 Saucy Salamander : Ubuntu 13.10 Saucy will be released on October 17th. Hope it will come with lot of improvements and ...0 comments |
- Install lamp with 1 command in Ubuntu 12.10, 13.04 Raring Ringtail & LinuxMint13 : Updated: 10/09/2012 :LAMP (Linux, Apache, MySQL and PHP) is an open source Web development platform ...0 comments |
- Setup IT And Asset Management System With GLPI On Debian/Ubuntu : GLPI is the Information Resource-Manager with an additional Administration Interface. You can use it...0 comments |
- Install FrostWire 5.6.9 In Elementary OS ‘Luna’/ Ubuntu / Linux Mint
- Setup IT And Asset Management System With GLPI On Debian/Ubuntu
- How To Configure Linux Clients To Authenticate Using OpenLDAP
- How To Install Netflix In Ubuntu
- cowsay And fortune Combined Together
- How To Show Username On Panel In Ubuntu 13.04/13.10
- Setup DNS Server On openSUSE 13.1
- TeamViewer 9 Final Has Been Released!
- Twelve Vulnerabilities Have Been Fixed In Ubuntu 12.04, Time To Update
- OpenLDAP Installation and Configuration in Ubuntu 12.10/13.04/13.10 And Debian 6/7
This work by unixmen.com is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
Copyright © 2008-2013 Unixmen.com .