Alias to ssh and cd into a specific directory

aliassshterminal

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?

Best Answer

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'"