Linux Terminal tip – avoid confusion

Sometimes when I’m really busy, I forget to look at the hostname and end up executing a command on the wrong computer. To solve this, I simply set up a couple of different profiles (one with a black background, one with white, etc.) and ssh into the box using a launcher which executes the following command:

gnome-terminal –window-with-profile=customprofile2 -e ‘ssh yourdomain.com’

This example is with Gnome terminal but if I remember correctly, you can do this with putty if you’re on Windows.




  • Andy Nguyen Apr 10, 2009, 8:32 pm

    Or, if like me, you have a hard time using both white-on-black and black-on-white windows, use different colors of (bash) prompt for different hosts.

    export PS1=”\[^[[47m\] `hostname` \w \[^[[0m\]\[^[[46m\]\!>\[^[[0m\] ”

    ^[[47m (ESC [ 4 7 m) and ^[[46m change the color of displayed characters; ^[[0m changes it back to no color.
    ^[[47;46m will turn on BOTH “colors” of 46 and 47, which is useful for setting a “reverse video” and a color at the same time for displayed characters.

    \! is the number of the command in the command line history.

    \w is the current working directory.

    The \[ and \] tells bash not to get confused by the zero-width “characters” like ^[ in the prompt string.

    To see that colors my “terminal” is capable of rendering, I usually do:

    i=1
    while [ $i -lt 255 ]; do echo “^[[${i}m —- $i —- ^[[0m”; ((i++)); done

    where “^[” is the ESC character. In “vi”, you would input that as ^V^[.