TTY command

Prints the file name of the terminal device connected to standard input on Unix and Linux systems to identify your current console

Last verified:

Visit TTY command

What is TTY command?

The tty command is a Unix and Linux utility that prints the file name of the terminal device connected to standard input. The term 'tty' stands for 'teletypewriter,' referring to the physical terminal devices that UNIX was originally run from. When you run the command without options, it outputs the path to your current terminal device, such as /dev/tty1, /dev/tty2, or /dev/pts/0 for pseudo-terminals.

TTYs are virtual consoles in Linux systems. By default, Ubuntu provides 7 TTYs: traditionally TTY1-TTY6 are command-line-only virtual consoles, while TTY7 runs the X session (your graphical desktop). On Ubuntu 17.10 and newer, the layout changed: GUI login is on TTY1, GUI desktop on TTY2, and command-line consoles on TTY3-TTY7. Users can switch between them using Ctrl+Alt+F1 through F7 keyboard shortcuts.

The tty command is primarily for system administrators, developers, and Linux users who need to identify which terminal session they are working in. It is especially useful when managing multiple terminal windows, troubleshooting scripts, or determining whether a script is running in an interactive terminal or a non-interactive environment like a cron job.

Key features include silent mode (-s) for checking terminal status without output, help documentation (--help), and version information (--version). The command returns exit status 0 when standard input is a terminal and exit status 1 when it is not, making it valuable for conditional scripting.

TTY command pricing

Pricing model: Freemium

Free - The tty command is part of the core Unix/Linux system utilities and comes pre-installed on all Linux distributions, Unix systems, and Unix-like operating systems. There are no paid plans, subscriptions, or additional costs. It is included in the GNU coreutils package and is open source under standard Unix licenses.

TTY command pros

  • Displays current terminal device path instantly
  • Works on Linux, Unix, Solaris, and FreeBSD
  • Silent mode (-s) for script conditional checks
  • Returns exit status for automation workflows
  • Helps distinguish interactive vs non-interactive shells
  • Useful for troubleshooting broken desktop environments
  • No installation required - pre-installed on all systems
  • Lightweight with minimal resource usage
  • Works over SSH sessions correctly
  • Helps manage multiple terminal sessions effectively
  • Can send signals to jobs on specific terminals
  • Simple syntax easy to remember and use
  • Returns 'not a tty' when input is not a terminal
  • Useful for scripting conditional terminal logic
  • Kernel-provided virtual console access

TTY command cons

  • Only shows terminal name, no additional details
  • No color output or formatting options
  • Does not work in non-terminal environments
  • Limited to current standard input only
  • No historical terminal session tracking
  • Cannot list all available TTYs at once
  • No built-in documentation beyond --help
  • Exit status 1 when piped or redirected
  • Does not show user information directly
  • No GUI or interactive mode available
  • Cannot switch between TTYs directly
  • Limited to text-only output
  • No cross-platform Windows support natively
  • Does not show active processes on TTY
  • Silent mode provides no visual feedback

Frequently asked questions about TTY command

What is tty7 in the command line?

TTY7 is traditionally the virtual console that runs your X session (graphical desktop) in Ubuntu. Up until Ubuntu 17.10, TTY1-TTY6 were command-line only and TTY7 ran your normal desktop. On Ubuntu 17.10 and newer, the GUI login screen is on TTY1, the GUI desktop is on TTY2, and command-line consoles are on TTY3-TTY7.

How do I access different TTYs?

Use the keyboard shortcut Ctrl+Alt+F1 through F6 to access command-line virtual consoles. To return to your graphical desktop session, use Ctrl+Alt+F7 (or Ctrl+Alt+F2 on Ubuntu 17.10 and newer). You can also use the chvt command with sudo privileges to change the foreground virtual terminal from the command line or SSH.

What does the tty command do?

The tty command prints the file name of the terminal connected to standard input. It displays which terminal device you are currently using, such as /dev/tty1, /dev/tty2, or /dev/pts/0 for pseudo-terminals in terminal emulators like GNOME Terminal.

What does 'not a tty' mean?

When the tty command outputs 'not a tty', it means the standard input is not connected to a terminal device. This typically happens when the command is run as part of a script, when output is being piped, or when running in a non-interactive shell like a cron job.

How many TTYs does Ubuntu have by default?

By default, Ubuntu has 7 TTYs. Traditionally, TTY1-TTY6 are command-line only virtual consoles and TTY7 runs the X graphical session. In Ubuntu 17.10 and newer, GUI login is on TTY1, GUI desktop on TTY2, and command-line consoles on TTY3-TTY7.

What is the -s option for tty command?

The -s (or --silent, --quiet) option makes the tty command run silently without printing any output. It only returns an exit status: 0 if you are in a terminal, and 1 if you are not. This is useful in scripts to check if a command is executing in an interactive terminal environment.

How can I check which TTY I am currently using?

Simply type 'tty' without any options to display your current terminal device path. You can also use 'who am i', 'w', 'ps ax|grep $$', or 'sudo fgconsole' to find information about your current terminal session and which virtual console is active.

Can I switch TTYs from SSH?

Yes, you can change the displayed TTY from SSH using the chvt command with sudo privileges. The command 'chvt N' makes /dev/ttyN the foreground terminal. The key combination Ctrl+LeftAlt+FN (with N in range 1-12) also has a similar effect.

What is the difference between tty and pty?

TTY (teletypewriter) refers to physical or virtual console terminals like /dev/tty1 through /dev/tty6. PTY (pseudo-terminal) refers to terminal emulators like those used in GNOME Terminal, xterm, or SSH sessions, which appear as /dev/pts/0, /dev/pts/1, etc.

Is the tty command available on all Unix systems?

Yes, the tty command is available on all Unix and Unix-like operating systems including Linux, Solaris, FreeBSD, macOS, and AIX. It is a standard utility that prints the terminal name connected to standard input and is part of the core system utilities.

Categories

Use cases

Browse all AI tools on NeedAnAI