Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

tty

Print the name of the terminal device you are using (like /dev/tty3 or /dev/pts/0).

Niveau
Dagelijks Linux
Groep
Shell en hulp
Root nodig
Nee
Pakket
coreutils

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

Every session has a terminal device: a real console (/dev/tty1 … /dev/tty6) or a pseudo terminal for terminal windows and SSH (/dev/pts/0, /dev/pts/1 …).

tty prints the name of yours. When the input is not a terminal (for example in a cron job or a pipe), it prints "not a tty" and returns an error code — scripts use this to know if a person is watching.

Zo schrijf je het

tty [OPTION]...

Opties 3

Meest gebruikt

-s, --silent, --quiet
Print nothing; only return the exit code (0 = terminal, 1 = not a terminal).
--help
Show help.
--version
Show the version.

Voorbeelden 11

$ als gewone gebruiker# als root (of met sudo)

  1. 1Which terminal am I on?

    tty
    /dev/pts/0

    pts = terminal window or SSH session.

  2. 2On the local text console

    tty
    /dev/tty3

    A real virtual console (Ctrl+Alt+F3).

  3. 3Check in a script if a person is watching

    if tty -s; then echo "interactive"; else echo "batch (cron, pipe)"; fi

    Ask questions only when a person can answer.

  4. 4In a pipe there is no terminal

    echo | tty
    not a tty

    stdin comes from the pipe, not from a terminal.

  5. 5Send a message to another session

    who
    write admin pts/1

    write and wall use the terminal names that tty and who show.

  6. 6End another session

    pkill -KILL -t pts/3

    Logs out the session on pts/3 (find it with who).

  7. 7Set terminal options for your session

    stty -a

    Shows the settings of the current tty (like the erase key).

  8. 8Log the terminal in a script

    echo "$(date) started on $(tty) by $USER" >> /var/tmp/run.log

    Helps to see later how and where a script was run.

  9. 9See the owner of your terminal device

    ls -l $(tty)
    crw--w----. 1 admin tty 136, 0 Oct 25 09:02 /dev/pts/0

    Your terminal belongs to you; group tty may write messages to it.

  10. 10Find processes attached to a terminal

    ps -t pts/0

    All processes of that session.

  11. 11Check that SSH gave you a terminal

    ssh server2 tty; ssh -t server2 tty

    Without -t a remote command has no terminal ("not a tty").

Tips om te onthouden

  • /dev/ttyN = console, /dev/pts/N = window or SSH. tty -s = test in scripts.

Volledige handleiding

Deze pagina legt het commando uit in eenvoudige woorden. De originele handleiding heeft elk detail.

In je terminal: man tty