Linux terminal is one of the most important development tools for software engineers (or production engineers). If you’d like to learn Linux, the first thing you might want to do is to get yourself familiar with terminal.
In this article, we’ll be briefly introducing Linux terminal.
When computers were invented, they were giant, which typically fit in a whole room. Like this
In order to interact with such a giant computer, people invented terminal, which is a much smaller device.
In short words, terminal is basically an input and output device for a computer.
After years of development, computers have become much smaller today. Today, when people refers to terminal, they do not mean the old terminal hardware device. What they mean is actually terminal emulator.
A terminal emulator is basically a software component which can emulate what the hardward devices had. For example,
Note that terminal is different from shells. Terminal is the GUI component that help you interact with the shells. Terminal does not understand what your input means. It simply forwards your input to the shells. Shells do not interact with you directly, but they do interpret whatever command stream that the terminal passes to it.
The following diagram explains how terminal works (in a simple case, where a shell running behind the terminal).
Here’s the what the data flow looks like:
- Users type in characters in the terminal GUI.
- The characters are sent to the terminal UI component, which are then forwarded to the input component.
- The terminal input component then forwards to the characters to a pty master device.
- OS will forward the characters from the master pty device to the slave pty device.
- The characters are then forwarded from the slave device to the shell.
- The shell interprets the command stream, and then send out the output stream to the pty slave device.
- The output streams are forwarded back from the pty slave device to the pty master device, to the terminal output component, and finally to the terminal GUI.
The data flows between terminal and terminal applications are basically of two types:
- Ascii Codes: This includes characters, enter, backspace, etc. Most of the data between terminal and terminal applications are in the form of ascii codes.
- Escape Sequences: Controlling the bahavior of the terminal, for example, the text color, the cursor movement.
Today, there are many terminal implementations. Here are some examples:
- Mac: iterm2, terminal
- Windows: Mintty
- Linux: xterm, urxvt, gnome terminal
If you’d like to understand more about terminal, check out this udemy course. The course discusses how terminal works, and also helps you set it up to make your more productive.