Tuesday, October 20, 2009

Unix commands

Having covered this much ground let us now get into the thick of the things. Most of us would be entering the Unix arena after traversing that of DOS. So just so as to feel at home, we will first have a look at some commands in Unix that are parallel to those available in DOS. The following things need to be remembered which apply to all Unix commands:
  • All Unix commands must always be entered in small case letters.
  • Between the command name and the options that may be available with the command there must always be a space or a tab. For example, ls -l. Here ls is the command whereas -l is the option and the two have been separated by a space. The option is usually preceded by a minus (-) sign. The options available with a command are often known as switches.
  • Two or more options available with a command can usually be combined. For example, the command ls -l -a is same as ls -la.
  • If you make a typing mistake, press Backspace to erase characters. Don't try to back using arrow keys and then attempt deleting using the Del key.
  • To cancel the entire command before you press Enter, press the Del key.
  • Don't turn off the computer if you have made a mistake and all is not going well. DOS users are used to just turning off the computer if a command behaves strangely, possibly by falling into an infinite loop or some other such thing. Unix doesn't respond well to such an approach. Instead we need to suggest politely to Unix to stop execution of the command which is creating a problem. One way to do so is by hitting the Del key. If still the command is not abandoned try Ctrd d and you would be returned to the login prompt. And if it is really a bad day for you even Ctrl d may not be able to do the job. At such times you got to contact the system administrator who would then kill your process from memory.

Monday, October 19, 2009

The first faltering steps

We have done enough homework on Unix now to venture for our first practical contact with it. Given that your terminal is secured to the host computer and is powered on, your display prompts you for your login name. Each user is given an unique login name & a password, which are like an entry pass to contact to the host machine as a user.

If you haven't been given a login name and a password, you won't be able to gain access to Unix. After you enter your login name, you are prompted to enter the password which when keyed in does not appear on the display. Obviously this is to ensure that no chance or may be premeditated passer-by is able to sneak it on it.

When you try to access your system, Unix wil display a prompt that looks something like this:

login: aa1
Password: heman1

After receiving the login prompt, you enter your login name (aa1 in the above example), after which you receive the Password prompt. At this stage you must type in your password (heman1 in the above example). The password of course would not appear on the screen. The password you use should be kept private. It is the method used by Unix to prevent unauthorized entry into the system. The password should be changed frequently. On many systems, after a specified period of time, your password expires (ages) and the next time you login the system requires you to change your password. In addition, you can change your password whenever you like on most systems by using a command to alter the password. We would discuss how to change your password later.

Sometimes you may not type the login name or password properly. When you do this, the system will respond with the following message:

login: aa1
Password: heman1
Login incorrect

Wait for login retry:

Note that the system does not tell you which one is incorrect, the login name or the password. Again, this is a security measure. Even if you type your login name improperly, you will still get the password prompt. You usually get three to five attempts to get it right before your terminal is disconnected. Many times a message is displayed to the system administrator telling him or her that several unsuccessful attempts were made on your login name.

Once the correct login name and password have been supplied, you find some welcome messages from the suppliers of the Unix version installed on the host machine, followed by a command prompt. The command prompt is a $ (dollar) if you are operating in Bourne shell or a % if in C shell. What powers await you here will be unwound as we progress. For now, take it from me that they do.

You are prompted for the login and the password every time you put on your terminal. Its purpose is to identify the user and allow access to the system only after verifying the identity of the user. You will not be prompted for the login if there is some problem in cables through which your terminal is connected to the host machine.

Once at the $ prompt you can issue commands. There are several hundred commands available in Unix. Let us begin with the most elementary one.

$ who am i
aa1 tty3a Jun 10 09:15

Thursday, October 15, 2009

Types of Shells in Unix

Different people implemented the interpreter function of the shell in different ways. This gave rise to various types of shells, the most prominent of which are outlined below:

Bourne Shell
Among all, Steve Bourne's creation, known after him as the Bourne Shell, is the most popular. Probably that's why it is bundled with every Unix system. Or perhaps it is the other way round. Because it was bundled with every system it became popular. Whatever the cause and the effect, the fact remains that this is the shell used by many Unix users. This will also be the shell we shall be talking about extensively throughout the blog.

C Shell
This shell is a hit with those who are seriously into Unix programming. It was created by Bill Joy, then pursuing his graduation at the University of California in Berkeley. It has two advantages over Bourne Shell. Firstly, it allows aliasing of commands. That is, you can decide what name you want to call a command by. This proves very useful when lengthy commands which are used time and again are renamed by you. Instead of typing the entire command you can simply use the short alias at the command line.

If you want to save even more on the typing work, C shell has a command history feature. This is the second benefit that comes with C Shell. Previously typed commands can be recalled, since the C Shell keeps track of all commands issued at the command line. This feature is similar to the one provided by the program DOSKEY in MS-DOS environment.

Wednesday, October 14, 2009

Unix system organization

The functioning of Unix is manned in three levels. On the outer crust reside the application programs and other utilities, which speak our language. At the heart of Unix, on the other hand, is the Kernel, which interacts with the actual hardware in machine language. The streamlining of these two modes of communication is done by the middle layer, called the Shell.

The Shell, or the command interpreter as it is called, is the mediator, which interprets the commands that we give and then conveys them to the kernel which ultimately executes them. You can imagine kernel as a monarch who is in overall control of everything, whereas the shell as its emissary.

The kernel has various functions. It manages files, carries out all the data transfer between the file system and the hardware, and also manages memory. The onus of scheduling of various programs running in memory or allocation of CPU time to all running programs also lies with the kernel. It also handles any interrupts issued, as it is the entity that has direct dealings with the hardware.

The kernel program is usually stored in a file called 'unix' whereas the shell program is in a file called 'sh'. For each user working with Unix at any time different shell programs are running. Thus, at a particular point in time there may be several shells running in memory but only one kernel. This is because, at any instance Unix is capable of executing only one program as the other programs wait for their turn. And since it's the kernel which executes the program one kernel is sufficient. However, different users at different terminals are trying to seek kernel's attention. And since the user interacts with the kernel through the shell different shells are necessary.

Tuesday, October 13, 2009

Salient Features of Unix ... continued

Unix has excellent provision for communicating with fellow users. The communication may be within the network of a single main computer, or between two or more such computer networks. The users can easily exchange mail, data, programs through such networks. Distance poses no barrier to passing information or messages to and fro. You may be two feet away or at two thousand miles, your mail will hardly take any time to reach its destination.

Unix allows sharing of data, but not indiscriminately. Had it been so, it would be the delight of mischief-mongers and useless for any worthwhile enterprise. Unix has three inherent provisions for protecting data. The first is provided by assigning passwords and login names to individual users ensuring that not anybody can come and have access to your work.

At the file level, there are read, write and execute permissions to each file which decide who can access a particular file, who can modify it and who can execute it. You may reserve read and write permissions for yourself and leave others on the network free to execute it, or any such combination.

Lastly, there is file encryption. This utility encodes your file into an unreadable format, so that even if someone succeeds in opening it, your secrets are safe. Of course should you want to see the contents, you can always decrypt the file.

One of the main reasons for the universal popularity of Unix is that it can be ported to almost any computer system, with only the bare minimum of adaptations to suit the given computer architecture. As of today, there are innumerable computer manufacturers around the globe, and tens of hundreds of hardware configurations. More often than not, Unix is running strong on each one of them. And lest we forget, due credit for this feat must be given to the Dennis Ritchie's prodigy, C, which granted Unix this hardware transparency. Unix, in fact, is almost entirely written in C.

Monday, October 12, 2009

Salient features of Unix

The Unix OS offers several salient features, the important of which are discussed below:

Multiuser capability
Among its salient features, what comes first is its multiuser capability. In a multiuser system, the same computer resources - hard disk, memory, etc. are accessible to many users. Of course, the users don't flock together at the same computer, but are given different terminals to operate from. A terminal, in turn, is a keyboard and a monitor, which are the input and output devices for that user. All terminals are connected to the main computer whose resources are availed by all users. So, a user at any of the terminals can use not only the computer, but also any peripherals that may be attached, say for instance a printer. One can easily appreciate how economical such a setup is than having as many computers as there are users, and also how much more convenient when the same data is to be shared by all.

At the heart of an Unix installation is the host machine, often known as a server or a console. The number of terminals that can be connected to the host machine depends on the number of ports that are present in its controller card. For example, a 4 port controller card in the host machine can support 4 terminals. There are several types of terminals that can be attached to the host. These are:
  • Dumb Terminals - These terminals consist of a keyboard and a display unit with no memory or disk of its own. These can never act as independent machines. If they are to be used they have to be connected to the host machine.
  • Terminal Emulation - A PC has its own microprocessor, memory and disk drives. By attaching this PC to the host through a cable and running a software from this PC we can emulate it to work as if it is a dumb terminal. At such times, however, the memory and the disk are not in use and the PC cannot carry out any processing on its own. Like a dumb terminal it transmits its processing jobs to the host machine. The software that makes the PC work like a dumb terminal is called Terminal Emulation Software. VTERM and XTALK are two such popularly used softwares.
  • Dial-In Terminals - These terminals use telephone lines to connect with the host machine. To communicate over telephone lines it is necessary to attach a unit called modem to the terminal as well as to the host. The modem is required to transmit data over telephone lines.

Sunday, October 11, 2009

Hardware Requirements for Unix

From the Lilliputian system on the PDP-11, Unix has emerged to be a rugged stalwart today. There are some prerequisites for a system that can host and take best advantage of it. These are an 80 MB hard disk and at least 4 MB of RAM (Random Access Memory) on a 16-bit microprocessor (80286, or preferably 80386/80486). So you need a PC/AT or higher with the aforementioned configuration to employ Unix to the best of its ability. And how do we connect the terminals to the host machine? Through a 4/8/16 port controller card installed in the expansion slot on the mother board of the host machine. One end of the cable is plugged to the port on the controller card and another end to the serial port (9 pin or 25 pin) of the terminal. Any DOS based machine with a serial port can act as a terminal.

Out of 80 MB disk space almost 40 MB is eaten away by the actual Unix OS files whereas another 10-20 MB is used as swap space. The swap space is used when Unix falls short of memory. At such times it temporarily stores in this swap space the contents of memory which are not immediately required. Whenever these contents are required they are read back from the swap space.

More the number of terminals more should be the memory on the host machine. As a thumb rule we can say that per terminal to be supported 0.75 to 1 MB should be present in the host machine.

Besides the hardware, Unix also requires a considerable amount of human support. This comes in the form of a System Administrator who supervises the working of Unix on any installation.