Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use one Mac to do work on several others.

What I'd like to do is find a way to programmatically set the title of a tab to the name of the server I'm ssh-ed into, so I can determine at a glance which tab I want to jump to to check on a particular server.

Anyone know how to do this?


share|improve this question
up vote 6 down vote accepted

Sure, this is an easy way to do it:

echo -n -e "\033]0; rules\007"

Just change " rules" to whatever you would like to title the session.

To capture the host name and post it to the title you could run something like this

name=`hostname`;echo -n -e "\033]0;$name\007"
share|improve this answer
Perfect. Just what I needed. – alesplin Mar 2 '12 at 0:24
This is awesome and works great. Is there a way to make this happy automatically upon launching Terminal and/or changing hosts? – Mitch Dec 15 '13 at 2:31

I wanted to do just this the other day and I came up with the following result:

put this in your .bash_profile / .bashrc file:

function tabname { printf "\e]1;$1\a"; }
function winname { printf "\e]2;$1\a"; }
function ssh() { echo "$@" | tabname `sed -E 's/(.*@)?([-a-zA-Z0-9\.]*)(.*)/\2/'`; /usr/bin/ssh "$@"; tabname; }

Automatically Changing Tab Names when using SSH

Hope this helps.

share|improve this answer
It uses a regular expression to pull out just the hostname. I'm only just learning regexes so anyone feel free to post a better solution if you can do it better. – Ben Mackey Dec 24 '12 at 3:06

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.