Saturday, March 16, 2013

pushd and popd directory stack commands

Traversing between multiple directories during software development can be irritating when the directory paths get longer than a few levels deep.  You'll likely need to move between where your source code is, a target directory where the source code is built, and then the deployment directory.

Instead of using the tried and true 'cd' and 'cd -' commands to only get back to the last directory you were in, pushd and popd are two easy commands for directory stack manipulation.  It's exactly what it sounds like - a stack, last in/first out.  It works in unix and dos, but my simple example here will be with cygwin installed on Windows 7.

$ pushd /home/cherryshoe/workspaces/project1
/home/cherryshoe/workspaces/project1 <wherever you were when you started>
$ mvn clean install
$ pushd target
/home/cherryshoe/workspaces/project1/target /home/cherryshoe/workspaces/project1 <wherever you were when you started>
$ cp SNAPSHOT.war /opt/app/apache-tomcat/webapp
$ pushd /opt/app/apache-tomcat/bin
/opt/app/apache-tomcat/bin /home/cherryshoe/workspaces/project1/target /home/cherryshoe/workspaces/project1 <wherever you were when you started>
$ startup.sh&
$ popd
/home/cherryshoe/workspaces/project1/target /home/cherryshoe/workspaces/project1 <wherever you were when you started>
$ popd
/home/cherryshoe/workspaces/project1 <wherever you were when you started>
$ popd
<wherever you were when you started>
$ dirs -v
 0 <wherever you were when you started>

You'll notice between each pushd and popd command, it'll show you what is currently on the stack.  If you want to suppress that you can redirect it to /dev/null.  You can then use 'dirs -v' to see there is no paths left on the stack

You can also save build and deployment time by using an class-reloader like JRebel, which I discussed a few posts ago.

No comments:

Post a Comment

I appreciate your time in leaving a comment!