Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

I have a nice little bash alias in my .bashrc folder that allows me to start Tomcat running without having to cd into the folder first, e.g.

alias startTomcat="cd ~/apache-tomcat-7.0.34/bin/ && ./"

However when I run startTomcatin a terminal, I'm booted out of the folder I started in, and now my terminal's residing in ~/apache-tomcat-7.0.34/bin/. This is expected behaviour, of course, but what I'd like to do is run the command without winding up in a different folder.

Can I either save the original location, then return to it in my .bashrc file, or alternatively run without cding out of the original folder?


share|improve this question

2 Answers 2

up vote 7 down vote accepted

You can use the absolute path for without to cd in the folder where is located::

alias startTomcat="~/apache-tomcat-7.0.34/bin/"

Or, you can use cd - which will return you to the directory where you were last time:

alias startTomcat="cd ~/apache-tomcat-7.0.34/bin/ && ./ && cd -"
share|improve this answer
Doh! I'd tried nearly that, but I assumed I'd have to add . to the front, and thus, it didn't run. Thanks! – yochannah Sep 3 '13 at 14:51

Radu's answer is good, but depending on use case you may want to use pushd and popd, which lets you save and restore directories. Something like: alias startTomcat="pushd ~/apache-tomcat-7.0.34/bin; ./; popd"

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.