One of the big differences between the mass-market windowing interfaces and the more powerful operating systems is the focus on a command-line interface.
Some command-line users scoff at the windowing interfaces, expressing an analogy with children's books: the avid reader graduates from picture books to the rich expressions found in prose; the expert computer user can likewise graduate from mouse pointers and icons to a more specific and literal command interface.
Some benefits to using the command line are consistency and automation. Rather than pushing and clicking many icons around the screen manually, a command line user can often perform a task once with a typed command, then have the computer repeat the task for a number of other similar operations very easily.
Even if the newcomer may prefer the graphical interfaces where available, much of Linux's power is not found in icons and widgets. Basic knowledge of the command line is important.
The Difference between Consoles, Terminals and Shells
When a user wants to edit a document, the computer must use a document editor. Likewise, when a user wants to open a direct command interface, the computer must display the interface in some way. Unix and Linux offer a lot of flexibility in offering this interface. There are three separate concepts involved.
The console refers to a screen and keyboard that are directly connected to the computer system. Usually, the console is positioned in the same physical room as the computer's cabinetry. Even without any network connectivity, the console is available for use by the system's administrator.
Unix and Linux computers can keep track of many distinct command sessions all at once. A terminal artificially emulates the physical hookup of a console. Many users may open terminal programs on their own computers to connect to a central server over the network. One user may use multiple terminal programs to view multiple sessions, even on the same console. The terminal just provides a communication channel for the user's input and output.
On most Linux distributions, a special arrangement is set up to offer several virtual text terminals, and optionally one virtual terminal for the graphical interface. When seated at the computer's physically-connected console, try pressing Ctrl+Alt+F1 to select virtual terminal number one. Ctrl+Alt+F2 will select virtual terminal number two, and so on. If there are six text terminals and a graphics terminal, then Ctrl+Alt+F7 will select the graphics display. Each terminal operates independently; log in and log out of each terminal separately to perform different tasks.
The term "terminal emulator" merely refers to a terminal application that is implemented in software, following the standards of dedicated terminal hardware that was once common in mainframe computing. There are several terminal emulator applications which run under the graphical windowing available on Linux, so a user can view their terminal output and their graphical applications at the same time.
Once the ability to type input and see the computer's output has been established with a console or terminal, the next concept is for the computer to run a command shell. A command shell, or just 'shell' for short, is a program that runs on the computer that offers a command line interface to the user. It listens to the user's typed commands, parses them, executes them, and then formats and displays the output back across to the user. Shells just prompt for commands, listen for commands, process commands, and prompt for more commands, endlessly repeating until the terminal is closed or the user logs out.
The default command shell for Linux is called bash. Others exist, such as csh, tcsh and zsh, which each offer unique features, but the vast majority of Linux users use bash.
Once the computer is running some type of command shell, it awaits the user's typed commands. A simple command might consist of the full filename of an executable file. For example, the command /bin/ls would list any files in the current directory.
However, since most commands are typed manually, shells have added a huge number of conveniences to make them simpler. The first and most important advance in command shell development was the concept of the environment, which is a collection of variables which could be used as a sort of shorthand for executing commands. While all Unix processes can interact with this library of variables called the 'environment,' it was the command shell that spurred its widespread adoption, and where most users interact with it.
The above example, /bin/ls, is a little cumbersome to type repeatedly. The environment has a variable called PATH which lists a few subdirectories to look for common executable files. Thus, if the PATH includes /bin, the user only needs to type ls to get a file listing. The 'ls' program is found in one of the directories on the searched PATH.
You can discover the value of a given environment variable with the echo command. Try echo $PATH to see the current search path for programs. Or try the set command all by itself to see all of the available defined environment variables at once.
Every user has their own home directory where they can put their own files. This is often in the /home directory, such as /home/joe for user joe's personal files. Usually, but not always. In fact, the home directory can be moved if necessary, such as when one storage device gets full and another storage unit must be added to a large server. The $HOME environment variable is set when a user logs into their account, to help any applications find the user's personal files.
The need for $HOME is so common, that bash takes it one step further. When a user types ~/ at the beginning of a filename, bash and other shells assume it is identical to $HOME/ instead. Many such shortcuts exist in bash; it may seem that bash will do anything to save a few keystrokes.
$TERM, $USER, $PS1
Depending on the type of terminal and other factors, there may be a few variables or many variables in the environment. New values can be assigned temporarily or exported for the rest of the shell session. Any program can create new variables for its own use or to communicate certain defaults to other programs.
Some variables are intended for the user's customization of their own bash sessions. For example, the $PS1 variable holds the prompt that bash displays before listening for user input. Set PS1 to a new value, and bash will use that value for the new prompt.
Lastly, the environment is inherited from one process to another. This means that one process typically cannot affect the environment of another process. Each new process gets a copy of the environment from its parent, and any customizations only take effect within that program or bash session.
Some helpful google searches may be linux command line tutorial, linux learning xterm shell, and linux learning bash shell.
Contact Ed Halley by email at
Text, code, layout and artwork are Copyright © 1996-2005 Ed Halley.
Copying in whole or in part, with author attribution, is expressly allowed.
Any references to trademarks are illustrative and are controlled by their respective owners.