Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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 want to automatically be put in a screen if I log in on a tty (if I'm using e.g. Terminal, I can simply open a new window instead.) I've already figured out the screen parameters and startup file configurations; I just need a reliable way to check whether the terminal is a tty, a terminal emulator, or something else. As far as I know, there are two main types of terminals: tty's (like the ones you can get to in Linux with ctrlaltF#) and terminal emulators (e.g. Apple Terminal, xterm, etc.)

What are the different types of terminals one is likely to encounter today, and how can I tell which kind the current session is in from a script?

(I have Linux and Mac systems, and I would like the test to work on both. If it requires a non-standard program, that should be available in the Debian, Ubuntu, and Homebrew repositories.)

share|improve this question

I know of two different types of (pesudo) terminals: tty and pts. ttys are the terminals reachable using ctrlaltF#. pts` are the terminals started inside gnome-terminal (or konsole if using kde, or xterm).

There is a command called tty which will tell you what terminal you are currently running on.

Output from running inside a gnome-terminal:

$ tty
/dev/pts/2

Output from running in ctrlaltF1

$ tty
/dev/tty1

I do not know whether there are more types of terminals. Those two are the only ones I have encountered in my many years of using linux.

Here are more information about terminals:

share|improve this answer
    
Ah…Macs seem to use a different system; I ran tty from a Terminal window and got /dev/ttys002. – Blacklight Shining Nov 19 '12 at 16:00
    
So…should I just assume there are only tty's and emulator programs, and check that the output of tty matches /dev/tty<number>? – Blacklight Shining Nov 19 '12 at 21:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .