Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I want an alias to SSH into another machine and then CD into a specific directory.

I try:

alias appl="ssh 9@lon.orb.com; cd /opt/tomcat/instances/"

It does not work. Any ideas?

share|improve this question
add comment

2 Answers 2

It doesn't work because the cd is executed on your local machine when the ssh does terminate.

Here is the way to do it:

alias appl="ssh 9@lon.orb.com 'cd /opt/tomcat/instances ; exec ${SHELL} -i'"
share|improve this answer
add comment

If you mean that the cd should work in the remote machine, then this cannot work.

You could change your ~/.bash_profile to do this cd for every login or just from certain machines.

share|improve this answer
add comment

Your Answer

 
discard

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.