MoonPoint Support Logo


Shop Amazon Warehouse Deals - Deep Discounts on Open-box and Used ProductsAmazon Warehouse Deals

Advanced Search
Sun Mon Tue Wed Thu Fri Sat

Wed, Jan 13, 2016 11:24 pm

Returning to a prior directory with Bash

If you use the Bash shell on a Unix/Linux system, you can return to the prior directory you were in using cd $OLDPWD or simply cd -. If you wish to be able to easily return to a prior directory further back, you can use the pushd and popd commands. The pushd command pushes the current directory onto a directory stack,i.e., each time you issue the command the current directory is added to the "top" of the stack. When you issue the popd command, you are returned to the directory that is currently at the top of that stack. So if you were in the directory /home/jdoe/test then issued the command pushd, later changed the working directory to /home/jdoe/abc and issued the command pushd again then the command cd /home/jdoe/def followed later by cd /home/jdoe/ghi, if you then issued the command popd, your current working directory would become /home/jdoe/abc. If you entered the popd command a second time without any intervening pushd command, you would be returned to directory /home/jdoe/test, the first directory pushed onto the stack.

[/os/unix/bash] permanent link

Once You Know, You Newegg AliExpress by

Shop Amazon Local - Subscribe to Deals in Your Neighborhood

Valid HTML 4.01 Transitional

Privacy Policy   Contact

Blosxom logo