Chapter 1

Dealing With Commandline Culture Shock

Where Did My Windows Go?

When you first boot Linux, you probably won't see a graphical user interface. And if you're only computer experience has been with the Macintosh, Windows 95, or some other windowing interface only, then the pervasive command line may come as a bit of a culture shock for you. Much of Unix happens right there next to the $ or the % symbol. Or the # if you're doing it as root, the Unix name for the system administrator. That's you, by the way.


Chapter Preview

This chapter will teach you the rudiments of getting comfortable at the Unix commandline. There are many commands you can issue at the commandline; it's probable that scarcely anyone knows them all. In this chapter you will learn 20 of the most useful ones: ls, cd, more, less, tail, pwd, mkdir, cp, mv, rm, alias (for use with color-xterm), cat, locate, updatedb, find, man, echo, clear, history, top, ps, the pipe symbol, and exit. This chapter will cover the following practice exercises:

  1. Find out what shell you're using
  2. Explore your home directory by listing its contents
  3. Look at your shell's resource files
  4. Examine the contents of some files in your home directory
  5. Create a temporary directory in your home directory
  6. Create a text file in your temporary directory
  7. Copy that file to a backup file
  8. Delete the first backup file
  9. Copy the backup file to the back to the file you deleted
  10. Rename the directory and its contents
  11. Locate your home directory on your system in relation to the root directory
  12. Use the locate and updatedb commands to find the files you created.
  13. Look at the history of your commands and copy them into a file.

Exercise 1: What is a Shell, and Which One Are You Using?

The first thing you see when you log into your freshly-installed workstation will be something like what appears in Figure 1.1. You won't see any pretty GUI inviting you to press a button or scroll a window. You see a commandline prompt like the good old DOS days. This is a command shell where you issue instructions to the system just like the old timers did it when Dad was a teenager. It's a healthy thing, the command shell.

Figure 1.1 Your First View of the Commandline Shell

A Root Window Screenshot

It probably looks like a lot of nothing, but it's perhaps the most powerful tool available in the entire system. From this simple location, the root account at the shell's command line, you can administer or destroy the entire system! Nearly everything, as far as system maintenance, can be done from this simple looking little environment here. And a great deal of user applications can be run from here too.

Here are some things to pay attention to in this figure above:

  1. The user who is using the shell--"root" in this case.
  2. The workstation name--"sylvester" is the name of my workstation.
  3. The pound sign, "#", indicates that this is a root shell with system administrator privileges.

When a normal user logs in, he will see a "$" sign instead of a "#" sign. That is if he is using a Bourne shell or clone. What am I talking about? Read on.

Types of Command Shells

Many types of command shells exist, and you may use nearly any of them on your system, according to your tastes. They each have different advantages and strengths. Some allow scripting that closely resembles the C programming languages, others allow for more macro language syntax, and others have yet other strengths. It all depends on your preferences and requirements.

Some of the popular shells are pdksh, bash, tcsh, ash, and zsh. The main differences between them apply to those who write shell scripts. If you're reading this lesson, the chances are you are too new to appreciate the differences anyway, so just stick with bash as your default shell.

Which Shell are You Using?

Any time you wish to find out which of these shells you are using, just type the following at the command prompt:

echo $SHELL

You'll get something back like the following:

[dsj@sylvester dsj]$ echo $SHELL
/bin/bash
[dsj@sylvester dsj]$

Exercise 2: Listing the Contents of a Directory.

Just like the cockpit of an airplane, your command shell contains instruments to read as well as system controls. One of the most common ``readings'' you'll take is listing the contents of a directory. Another is reading the contents of a single text file, but we'll look at how to do that later. You'll list directory contents often when you want to find a file or look at file permissions (Unix security settings for individual files), and many other such routine tasks.

What's In Your Directory?

One of the most commonly shell commands used is ls. It stands for 'list' the contents of a directory. Once you get used to the command line, you'll use the ls command constantly, just as you might use the file manager under Microsoft Windows. The beauty of the commandline over a file manager is that you can do anything from the command line. From the file manager, you can only do what is listed on a menu or in a button.

Note: Command ``Switches''

The ls command contains many switches; they appear as hyphens followed by letters or combinations of letters. These add flexibility to the command, and all commands at the prompt similar to ls, and adjust the output to your needs.

Example: ls -alR

The -alC are ``switches'' that tell the program to list all files, even those hidden files that start with a period (normally hidden in Unix), to make a ``long'' listing including filesize, datestamp, and file permissions. The ``R'' tells the program to list recursive directories after listing the current directory. That means this command will list not only everything in the current directory, but everything in nested subdirectories also.

You may not want to use the -R switch very much because often it will fill your screen with more than you can read.

For a complete list of switches type man ls or info ls. These commands invoke further sources of documentation for ls.

Find out what is in your directory by typing ls now. What do you see? If you've just created your first user account you probably won't see very much yet. Or if you've just visited the root account for the first time, you probably won't see much more than is listed in Figure 1.2 below.

Figure 1.2 Your First Directory Listing.

View of your first directory listing

You'll notice this listing might even have more than your listing shows. This account has resource files for several programs you may or may not have run. A resource filename usually begins with a period and ends with an ``rc''. Thus, .bashrc is the resource file for bash, the command shell you happen to be using. .pinerc is the resource file for pine, an email program. And so on.


Exercise 3: Viewing Individual Text Files

How do I look at individual text files?

Many files you see listed in your directory are text files. That is, they do not require any special software to view them. Some files, called binary files, can only be viewed with special software. Text files may be viewed by using any of several command utilities, as well as any Unix text editor.

Note: Text Editors and Linux

The resource files mentioned above (those ``.*rc'' files) are pervasive in Unix and very important to how your system operates. Many key system components use those text files to determine how they run. The beauty of those key resource files being plain text is that they're easy to fix. No special tools required. Just any old text editor, even vi will do the job.