1913

10 分钟

#Bash 的 tty 命令

tty [OPTION]...

功能

查看连接到标准输入的终端文件名。

类型

可执行文件(/usr/bin/tty),属于 coreutils

参数

  • OPTION 选项:
    • -s, --silent, --quiet - 不打印任何内容,仅通过返回值返回状态
    • --help - 显示帮助
    • --version - 显示版本

返回值

  • 0 - 标准输入是终端
  • 1 - 标准输入是非终端文件
  • 2 - 参数错误
  • 3 - 发生写错误
  • 5 - 无法确认终端名称

#示例

$ tty /dev/pts/7

#推荐阅读

#手册

TTY(1) User Commands TTY(1) NAME tty - print the file name of the terminal connected to standard input SYNOPSIS tty [OPTION]... DESCRIPTION Print the file name of the terminal connected to standard input. -s, --silent, --quiet print nothing, only return an exit status --help display this help and exit --version output version information and exit AUTHOR Written by David MacKenzie. REPORTING BUGS GNU coreutils online help: <https://www.gnu.org/software/coreutils/> Report any translation bugs to <https://translationproject.org/team/> COPYRIGHT Copyright © 2023 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. SEE ALSO Full documentation <https://www.gnu.org/software/coreutils/tty> or available locally via: info '(coreutils) tty invocation' GNU coreutils 9.4 April 2024 TTY(1)

创建于 2025/12/6

更新于 2025/12/6