LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   pushd popd dirs (https://www.linuxquestions.org/questions/linux-newbie-8/pushd-popd-dirs-594922/)

christianunix 10-26-2007 09:35 PM

pushd popd dirs
 
Could you tell me a little bit about those commands? using examples... thanks!

bigrigdriver 10-26-2007 10:10 PM

Pushd, popd, and dirs are intended for folks who spend a lot of time working from the command line.

Here's an example of how it works.

Let's say you need to go to ~/docs, a docs folder in your home directory. Instead of giving the command 'cd ~/docs', give the command 'pushd ~/docs'. That puts ~/docs at the top of the directory stack (if you run the command 'dirs' without parameters, it will show you ~/docs in the stack).

Now you need to go to ~/music for some reason, but you will need to return to ~/docs. Give the command 'pushd ~/music' to add ~/music to the stack. The dirs command will now show you: ~/music ~/docs in the stack.

To quickly get back to you docs, you give the command 'popd +1' to get to the second directory in the stack (~/docs). But, at the same time, you remove ~/docs from the stack. Dirs will only show ~/music in the stack.

If you need to go back to music again, use the pushd option to add docs back to the stack.

In this example I've used short paths. Pushd and popd don't show their worth until you are working with long paths in your commands.


All times are GMT -5. The time now is 01:16 AM.