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.
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:
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.
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:
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.
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.
Any time you wish to find out which of these shells you are using, just type the following at the command prompt:
You'll get something back like the following:
[dsj@sylvester dsj]$ echo $SHELL /bin/bash [dsj@sylvester dsj]$
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.
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.
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.
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.