原文地址 stackexchange:What is the exact difference between a 'terminal', a 'shell', a 'tty' and a 'console'?
(原文wiki链接在翻译中替换为百度百科链接。)
A terminal is at the end of an electric wire, a shell is the home of a turtle, tty is a strange abbreviation and a console is a kind of cabinet.
终端在电线的末端,壳是乌龟的家,tty是一个奇怪的缩写,控制台是一种柜子。
Well, etymologically speaking, anyway.
从词源学上讲,是这样。
In unix terminology, the short answer is that
在unix术语中,简短地回答是:
- terminal = tty = text input/output environment
- console = physical terminal
- shell = command line interpreter
- terminal(终端) = tty = 文本输入/输出环境
- console(控制台) = 物理终端
- shell(壳) = 命令行解释器
Console, terminal and tty are closely related. Originally, they meant a piece of equipment through which you could interact with a computer: in the early days of unix, that meant a teleprinter-style device resembling a typewriter, sometimes called a teletypewriter, or “tty” in shorthand. The name “terminal” came from the electronic point of view, and the name “console” from the furniture point of view. Very early in unix history, electronic keyboards and displays became the norm for terminals.
控制台,终端和tty联系密切。最初,它们代表一台可以与计算机进行交互的设备:在unix的早期,它代表(teleprinter)电传打字机-外形类似打印机,也叫teletypewriter,或者缩写为"tty"。“终端”是从电子的角度看,“控制台”是从设备的角度看。在unxi的最初阶段,键盘和显示器成为终端的标准。
In unix terminology, a tty is a particular kind of device file which implements a number of additional commands (ioctls) beyond read and write. In its most common meaning, terminal is synonymous with tty. Some ttys are provided by the kernel on behalf of a hardware device, for example with the input coming from the keyboard and the output going to a text mode screen, or with the input and output transmitted over a serial line. Other ttys, sometimes called pseudo-ttys, are provided (through a thin kernel layer) by programs called terminal emulators, such as Xterm (running in the X Window System), Screen (which provides a layer of isolation between a program and another terminal), Ssh(which connects a terminal on one machine with programs on another machine), Expect (for scripting terminal interactions), etc.
在unxi术语中,tty是一种特殊的设备文件,它实现了一些额外的读写命令(ioctls,io设备控制函数)。一般,终端与tty同义。内核提供了一些代表硬件设备的tty,例如来自键盘的输入和到文本模式屏幕的输出,或在串行上传输的输入输出流。另一种tty,有时也被称为伪tty,是通过终端模拟器程序提供的(通过一个核心层),终端模拟器程序包括如Xterm(运行在X Windox System),Screen(提供了一个程序与另一个终端之间的独立中间层),SSH(在一台机器上连接另一台机器的终端的程序),Expect(脚本终端交互)等等。
The word terminal can also have a more traditional meaning of a device through which one interacts with a computer, typically with a keyboard and display. For example an X terminal is a kind of thin client, a special-purpose computer whose only purpose is to drive a keyboard, display, mouse and occasionally other human interaction peripherals, with the actual applications running on another, more powerful computer.
terminal这个词还有一个更传统的意思,它表示一台可以与计算机交互的设备,通常是键盘和屏幕。例如X terminal是一种瘦客户端,瘦客户端是一种特殊用途的计算机,它的唯一目的是驱动键盘,显示器,鼠标以及一些其它的人机交互外设,实际的程序运行在另一台更强大的计算机上。
A console is generally a terminal in the physical sense that is by some definition the primary terminal directly connected to a machine. The console appears to the operating system as a (kernel-implemented) tty. On some systems, such as Linux and FreeBSD, the console appears as several ttys (special key combinations switch between these ttys); just to confuse matters, the name given to each particular tty can be “console”, ”virtual console”, ”virtual terminal”, and other variations.
控制台通常是物理意义上的终端,一个直接连接到机器上的主终端。控制台在操作系统上通常表现为一个(内核实现的)tty。在一些系统中,如Linux和FreeBSD,控制台表现为多个tty(通过特定的组合键在tty之间切换),让人混乱的是,每个特定的tty的名称可以是"console"(控制台),"virtual terminal"(虚拟终端)等等。
See also Why is a Virtual Terminal “virtual”, and what/why/where is the “real” Terminal?.
参考Why is a Virtual Terminal “virtual”, and what/why/where is the “real” Terminal?.
A shell is the primary interface that users see when they log in, whose primary purpose is to start other programs. (I don't know whether the original metaphor is that the shell is the home environment for the user, or that the shell is what other programs are running in.)
shell(壳)是用户登录系统时看到的主界面,它主要的作用是启动其它程序。(我不知道原来的喻义是指shell是用户的home环境,还是shell是其它程序的运行环境。)
In unix circles, shell has specialized to mean a command-line shell, centered around entering the name of the application one wants to start, followed by the names of files or other objects that the application should act on, and pressing the Enter key. Other types of environments don't use the word “shell”; for example, window systems involve “window managers” and “desktop environments”, not a “shell”.
在unix圈中,shell特指命令行shell,围绕输入想要启动的程序名称,后面跟着文件名或者其它应用程序需要知道的东西,然后按回车键。其它类型的环境不使用"shell"这个词;例如,窗口系统包括"窗口管理器"和"桌面环境",而不是"shell"。
There are many different unix shells. Popular shells for interactive use include Bash (the default on most Linux installations), zsh (which emphasizes power and customizability) and fish (which emphasizes simplicity).
有很多不同的unix shell。流行的交互式shell包括Bash(大多数Linux默认安装),zsh(注重功能和可定制性),fish(注重简单)。
Command-line shells include flow control constructs to combine commands. In addition to typing commands at an interactive prompt, users can write scripts. The most common shells have a common syntax based on the Bourne_shell. When discussing “shell programming”, the shell is almost always implied to be a Bourne-style shell. Some shells that are often used for scripting but lack advanced interactive features include the Korn shell (ksh) and many ash variants. Pretty much any Unix-like system has a Bourne-style shell installed as /bin/sh
, usually ash, ksh or bash.
命令行shell包括了组合命令的流程控制结构。除了在交互式提示符中键入命令外,用户还可以编写脚本。大多数shell使用一套基于Bourne_shell的语法。当讨论"shell编程"是,shell通常指Bourne-shell风格的shell。一些shell经常用来运行脚本但是缺少高级的交互特性,包括the Korn shell(ksh)和ash的变种。几乎所有的类Unix系统都有一个Bourne-style的shell安装在/bin/sh,通常是ash,ksh或者bash。
In unix system administration, a user's shell is the program that is invoked when they log in. Normal user accounts have a command-line shell, but users with restricted access may have a restricted shell or some other specific command (e.g. for file-transfer-only accounts).
在unix系统管理中,一个用户的shell是指他们登录时被调用的程序。普通用户拥有一个命令行shell,但限制权限的用户会拥有一个restricted shell或者只能运行特定命令的shell(如仅用于文件传输的账户)。
The division of labor between the terminal and the shell is not completely obvious. Here are their main tasks.
terminal(终端)和shell的分工并不十分明显。它们的主要任务:
- Input: the terminal converts keys into control sequences (e.g. Left →
\e[D
). The shell converts control sequences into commands (e.g.\e[D
→backward-char
). - 输入:terminal将键盘操作转换为控制序列(如 Left -> \e[D)。shell将控制序列转换为命令(如 \e[D -> backward-char)。
- Line edition, input history and completion are provided by the shell.
- The terminal may provide its own line edition, history and completion instead, and only send a line to the shell when it's ready to be executed. The only common terminal that operates in this way is
M-x shell
in Emacs.
- The terminal may provide its own line edition, history and completion instead, and only send a line to the shell when it's ready to be executed. The only common terminal that operates in this way is
- 行编辑,输入历史和补全是shell提供的。
- terminal可能会提供自己的行编辑,输入历史和补全,并且只在准备执行命令的时候将命令发送给shell。主流的terminal中唯一这样做的是Emacs中的M-x shell。
- Output: the shell emits instructions such as “display
foo
”, “switch the foreground color to green”, “move the cursor to the next line”, etc. The terminal acts on these instructions. - 输出:shell发出指令如"display foo", “switch the foreground color to green”, “move the cursor to the next line”等,终端响应这些指令。
- The prompt is purely a shell concept.
- 提示符是shell中的概念。
- The shell never sees the output of the commands it runs (unless redirected). Output history (scrollback) is purely a terminal concept.
- shell中看不到它运行的命令的输出(除非重定向)。输出历史(回滚)是terminal中的概念。
- Inter-application copy-paste is provided by the terminal (usually with the mouse or key sequences such as Ctrl+Shift+V or Shift+Insert). The shell may have its own internal copy-paste mechanism as well (e.g. Meta+W and Ctrl+Y).
- 应用程序之间的复制粘贴是terminal提供的(通常用鼠标或键盘组合如: Ctrl+Shift+V 或 Shift+Insert)。shell也有自己的内部复制粘贴机制(如 Meta+W and Ctrl+Y)。
- Job control (launching programs in the background and managing them) is mostly performed by the shell. However, it's the terminal that handles key combinations like Ctrl+C to kill the foreground job and Ctrl+Z to suspend it.
- 作业控制(在后台启动程序并管理程序)主要有shell执行。然而,terminal处理组合键如Ctrl+C 来终止前台程序, Ctrl+Z来挂起前台程序。
扩展阅读:
CSDN:控制台,终端,虚拟终端,tty,shell等概念的区别
百度文库:Linux中tty、pty和pts概念及区别