Find Out What tty I’m Using tty command under Linux / Unix

In Linux or Unix, you can use the tty command to find out what terminal you are currently using. The command will display the file name of the terminal connected to the standard input.

tty

If you are logged in to a terminal session, the command will return the device name of the terminal, such as /dev/pts/0 or /dev/tty1.

If you are logged in remotely via SSH, the command will return the name of the pseudo terminal, such as /dev/pts/1.

If you are running the command in a script and you want to check if the script is running interactively or not, you can use the following command:

if [ -t 0 ]; then echo "Running interactively"; else echo "Running in a script"; fi

This command checks if the standard input (file descriptor 0) is connected to a terminal (-t 0), and if so, it outputs “Running interactively”, otherwise it outputs “Running in a script”.

You can also use who am i command which gives more information about the current session, like username, terminal and date and time of the session.

who am i

Please note that the tty command is not available on Windows systems.

(manafort.com)

Leave a Comment