1.2 Using the Shell

1.2 Using the Shell

When you installed Linux, you set up a root (superuser) password, and hopefully you also made at least one more regular user for yourself. For this chapter, you should log in as the regular user.

The first thing you need to do after logging in is to bring up a shell window. After starting a shell, its window contains a prompt at the top that usually ends with a dollar sign ($). On Red Hat Linux, the prompt looks like [name@host path]$. If you know Windows, you will find that the shell window looks vaguely similar to the command prompt.

Note?

You may hear the shell window referred to as the terminal window. The terminal window is the part of the user interface that accepts keystrokes from the windowing system and draws the characters on the screen. You can think of the terminal as a middleman between the shell and the user.

Now type the following command and press ENTER:

cat /etc/passwd

The command prints a couple of lines that start with usernames, and then you get your shell prompt back. If you can't read the text very well, manipulate the font settings to your liking. You're going to be spending a good part of your time with this book in the shell, so you should be comfortable with it.

The cat command is a great one to start with because it's one of the easiest Unix commands. Its syntax is as follows:

cat file1 file2 ...

When you run this command, cat prints (and concatenates) the contents of file1, file2, and any additional files you desire (denoted by ...) and exits.

If you do not specify any input files, cat reads from the standard input, which in this case is the keyboard. To see this at work, type cat and press ENTER. Unlike the earlier example, you do not get your shell prompt back because cat is still running. Now type some stuff (it doesn't matter what). After you press ENTER at the end of each line, cat repeats the line you typed. When you're sick of this, press CONTROL-D on a line by itself to terminate the cat command and return to the shell prompt.

Note?

Do not confuse CONTROL-D and CONTROL-C. CONTROL-D on a line by itself stops the current standard input entry (and often terminates a program). CONTROL-C terminates a program regardless of its input or output.

You have now experienced standard input (stdin) and output (stdout), two important components of the Unix shell environment. Standard input is a program's default input source. When you ran cat without any arguments, it didn't give up because there were no arguments; instead, cat switched to standard input instead of going after some files. Here, standard input was the stuff that came from your keyboard. Standard output, on the other hand, is where a program's output goes by default. In this case, that location is the terminal window running the shell. The best feature of standard input and output is that you can easily send them to places other than their defaults, as described in Section 1.14.