Thursday, October 04, 2007

Manage Adding Directories to a Stack with pushd

While working on my FreeAdLists personal project at home, I decided it was time to better manage my pwd efforts. I quickly grew weary and impatient (exacerbated by the fact I'm fighting a nasty cold and acute rhinitis) of changing directories so many darn times, so I decided it was time to use a stack (stack starts with 0). Here are few examples of the pushd and dirs commands, which pushes a directory and displays a stack, respectively.

# csh
# cd /
# pushd `pwd`
/ /export/home/esoft/xml/XMLDIR /opt/apps/apps1
# pushd /usr/local/popper
# dirs
/usr/local/popper / /export/home/esoft/xml/XMLDIR /opt/apps/apps1
# pwd
/usr/local/popper

Switches between the first two directories paths
# pushd
/ /usr/local/popper /export/home/esoft/xml/XMLDIR /opt/apps/apps1
# dirs
/usr/local/popper / /export/home/esoft/xml/XMLDIR /opt/apps/apps1
# pwd
# /

Moves /export/home/esoft/xml/XMLDIR to the top of the stack
# pushd +2
/export/home/esoft/xml/XMLDIR / /usr/local/popper /opt/apps/apps1
# dirs
/export/home/esoft/xml/XMLDIR / /usr/local/popper /opt/apps/apps1
# pwd
/export/home/esoft/xml/XMLDIR

No comments: