Before we can start issuing commands, it is important for us to understand how the Unix operating system receives these commands.
Most operating systems use an interpreter between the keystrokes the user enters and the language the computer needs to carry out the requested actions. In Unix, this interpreter is called the shell. It is analogous to the DOS shell on a PC and can be thought of as the way the user interfaces with the underlying operating system. The following analogy may help in understanding the role of the shell:
Imagine that you are under the ocean in a deep sea submersible. You do not interact with the ocean directly, but with a series of tools provided by the submersible: grabber hands, lights, and so forth. Unix is like the ocean, and the shell is like the submersible: it provides you with tools to interact with the operating system, and these tools come in the form of commands that you type at the keyboard. The shell translates what you type at the keyboard into something that the operating system can understand.
A diagram depicting how the shell interacts with the operating system, utilities, hardware, and the users is below.
There are several shells available in Unix: C, Korn, Bourne, Bourne-again, and so on. Each shell provides you with a different set of commands for communicating with the operating system. The user decides which shell to use based on which types of functions and controls they need. The C-shell, for example, gives the user an environment that acts like the C programming language. The commands you will learn today apply to all the shells.
NOTE: We will use the Bourne-again shell (bash) with our mercury accounts.
Using the Command Prompt
The first time you log into Unix, you may think that it isn't very user friendly: the computer just gives you a cursor, or prompt, and waits for you to type something. The prompt is asking what you want it to do and is waiting for an answer. Unlike graphical or menu-driven operating systems, Unix is command driven. You must type a Unix command at the prompt for the system to know what action to perform.
The look of the prompt may vary depending upon the setup of your Unix account. Common prompts include: $,%, and ~. Some systems also include the name of the host or the path of the directory.
Understanding Command Syntax
Syntax is to a computer like punctuation was to your 7th grade English teacher, except computers have no mercy. The spaces, minus signs, slashes, etc. must all be exactly right or else the computer will return an error message to you.
The simplest syntax is: [command] Enter, where you type a command, and then press Enter to tell Unix to process the command. Throughout this workshop you will notice syntax of commands presented in brackets. As we progress, the syntax will become a little more complicated.
Issuing Commands
Unix commands are usually short abbreviations for actions to be performed. Because commands are short, their meanings are not always obvious. Consider the commands ls, chmod, mkdir, cp, mv, cd, and pwd.
Unix commands are very useful to learn because they can be applied to so many different systems worldwide.
We can see our current Unix account settings, including our shell, by using the set command.
Step 1.To see your current settings, type:
set Enter
The host returns some information about your account settings. Your shell will be at the end of the line that starts "SHELL."
You see your default shell is the Bourne-again Shell:
SHELL=/bin/bash
On the line that begins with "PWD," you will also see information about your home directory, or opening directory, which is the location of your account on the server.
Your home directory is listed as:
PWD=/fs/username
The whocommand gives us the usernames of everyone logged into the same machine as us.
Step 2.To find out who else is logged onto the system, type:
who Enter
We should see a list of all other users who are currently logged into the same machine.
Sometimes you may want to clear the contents of the screen.
Step 3.To clear the screen, type:
clear Enter
The screen is now clear.
With the Bourne-again shell we can use the up and down arrow keys on the keyboard to see commands we have previously typed.
NOTE: Not all shells support this ability.
Step 4.To see the previous command, press:
Up Arrow key
Step 5.Use your up and down arrows to view the previously entered commands
Step 6.To reissue a command, with that command at the prompt, press:
Enter