الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

tty

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

المستوى
لينكس اليومي
المجموعة
الطرفية والمساعدة
يحتاج root
لا
الحزمة
coreutils

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

ماذا يفعل

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.

طريقة الكتابة

tty [OPTION]...

الخيارات 3

الأكثر استخدامًا

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

أمثلة 11

$ مستخدم عادي# بصلاحية root (أو مع 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").

نصائح للحفظ

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

الدليل الكامل

هذه الصفحة تشرح الأمر بكلمات بسيطة. الدليل الأصلي فيه كل التفاصيل.

في الطرفية: man tty