Ubuntu insights, Programming in groovy, java, et als!

Thursday, March 08, 2012

Coffee with Linux #2 - The Shell

Generally, users interact with the Operating System by clicking on icons, menus and buttons. This is called Graphical User Interface (GUI). Apart from this, there is also an other way to interact with the computer using a command line interface (CLI) which is purely by typing in commands to get the task done. Think of it the DOS command prompt in the world of Windows. One can open Notepad application either by selecting it from the start menu or by simple typing in notepad on the windows prompt. In a parallel context, the command line interface on Linux that enables human-machine interaction is called 'The Shell'. That being said, it is not technically correct to draw a comparison between the Windows DOS prompt and the Linux shell because the shell is capable of doing much much much more than what can be done from a regular dos prompt on windows.

The shell has many variants, some of which are 
  • C Shell
  • Korn
  • Bash
  • Z shell
Bash is used as a default for many Linux distros that are available today. In almost all Linux distros you find an option called terminal emulator (or simply the terminal). The terminal is merely a window that runs the shell program within it.

Standard input & Standard output

What you type in to the terminal on Linux is called the standard input and the output of the command typed in is called the standard output. This happens via streams. Whatever is typed in, is taken onto a stream (stdin) which is a continuous set of bytes, likewise the output is also written onto a stream (stdout) that is by default shown on the screen. You can redirect this stream, the standard output on screen onto a file or anywhere else. Example :

$ ls > outputOfLSCommand.txt

Speaking of streams there is a separate stream for carrying the error output (stderr). Likewise you can also redirect the standard input from a file instead of defaulting it to the keyboard.

Piping the output

Just the way the output is redirected, the user can also pipe the output. Piping generally happens when the output of one command is given as input to an other command. Example

$ ls | rev

In this command the output of list directories command as a String is given as an input to the rev (the reverse) command which displays the output text in a reversed way.

*********** End of Tutorial 2 ***********

See Introduction Tutorial 1: Coffee with Linux #1 - Head Start


Post a Comment