This section should provide a basic overview of Unix for someone who doesn't know anything about it. If you do, you can skip to the next chapter. If you don't, this will only be a snippet of knowledge, and you need to get a real Unix book to put by your bedside, alongside the USAH (which covers this ground most excellently), HLE, and Unix Power Tools [Powers+ 02] (hereafter called UPT). The goal here is not to explain every nuance of Unix but to make the first-time user aware and knowledgeable enough to ask the right questions. We hope that sometimes simply a mention is enough to get you to ask the right questions.
First, Linux is primarily used through a command line interface . You open a terminal shell and enter text commands on the command line ”see Figure 2.1 for an example of the ls and date commands entered into a shell. You probably installed one or more of the Linux desktop graphical interfaces, Gnome or KDE. When your Linux system boots, it will probably come up with a login to this graphical interface.  After logging in to the GUI as a normal user, you can open a terminal shell (look in the menus ), work from there, and log in as root from there.
Figure 2.1. The shell command line interface
Once you open a terminal shell, you can get information on any of the commands by using the Unix man (short for manual) system. The command man man gives you information on how man works. Each of these pages gives information on the valid options for the command. Some provide examples and pointers to other, similar commands. If you don't know the name of the command, you can do man -k commandname . This often gets you much more information than you want, so you can pipe it through a pager such as less or more : man -k commandname less .
Most Linux distributions come with some sort of desktop to give you that Apple/Windows feel, and these work fine ”even better than Apple/ Windows in some respects, because OS X and XP have yet to come up with anything equivalent to the multiple virtual desktops that are standard in Gnome and KDE. But since much of the work that has to be done in web site development and administration has to be done as root , it's still better to do most things in a shell through the command line. You can move files and folders (in Unix, folders are really directories) via a graphical window interface, but you typically don't want to do this as root . It's better to learn how to drive a stick ”you have more control.
You have many choices for your shell interface. This is a Good Thing, because we all have different preferences. Many, if not most, people go with bash as their shell interpreter (largely because bash is the default shell when Red Hat is installed). Others prefer tcsh , a variation on the original csh . There are also zsh and ksh . You can pick and choose. If you are new to this, go with the default on your system until you know enough to have a preference.
The preferences for your shell are found in .tcshrc or .bashrc or .zshrc , and so on (use ls -a to see the normally hidden files that start with a " . "). Even if you haven't created a local .tcshrc , a systemwide resource file provides global defaults. Most Unix folks pick a shell, develop an extensive customized dotfile (as these things are called ”there are also dotfiles for X Windows, Gnome, KDE, SSH, and combing your hair), and just move it around from system to system. There is also a dotfile generator, which you can use to create dotfiles for many different programs until you get the hang of it (www.blackie.dk/dotfile/).
You can change the shell with the chsh command, which asks for a password.
2.2.2 Owner, Groups, Permissions, Ownership
Everything in Unix is a file, and each of the files has associated with it an owner and a group . If you do an ls -l in a directory, you might see something like Table 2.2, though it won't have column titles like those shown here.
The long listing shows that J. Random Luser ( jrl ) owns three files ( junk.txt , foo.html , and bar.cgi ) and one directory ( bin ) in this directory. The permissions of junk.txt are such that the owner of the file ( jrl ) and the group associated with the file ( jrl ) can read and write the file, and the rest of the world can read it. The file foo.html is a bit more private, and only jrl can alter it, though staff members may view its contents. The world cannot see it at all. The file bar.cgi appears to be an executable, and J. Random Luser can change it, staff can view it, and both staff and he can execute it.
Table 2.2. Sample Directory Listing
The ownership of a file can be changed using the chown command, and the permissions changed via chmod . A typical thing to do would be chmod a+x bar.cgi , which would change the permissions to allow all to execute it. Similarly, one could change the permissions via chmod go-r junk.txt to allow only the owner to read the file.
Old-school Unix types like to use the octal numeric mode to change file permissions, thus leading to such commands as chmod 666 foo.bar . The value 666 is an octal number representing the three permission groups: user/group/world. If the value of one of the groups is 6 , the permissions are "read on, write on, execute off," represented as rw- . Therefore, 666 represents rw-rw-rw- . The value 751 would be rwxr-x--x . Other file attributes, such as the sticky bit, can be changed with these commands; use man chmod to see all the possibilities.
Every object in Unix is a file; everything that runs is a process . Some run once and quit; others run constantly in the background as daemons . Each process has an owner and a process ID (PID). The owner is important because that's who controls the process ”J. Random Luser can't kill rootly processes, though root can kill JRL's processes. There are also subtler issues with process ownership ”processes that run under root ownership are vulnerable to being cracked and allowing the cracker to gain root access (which is very bad).
Useful commands associated with processes are ps , which shows the processes running, and top , which gives an overview of the processes running. End top with q . There are many useful options for these programs ”as usual man function is a good place to start. Another useful command is man-k best guess at a useful function .
Unix is not perfect, of course, and sometimes a process gets out of hand and must be terminated . The appropriate command for this is either kill or killall .  The kill command takes as its argument a PID gotten from ps or top , and killall works on a command name. Typical usage is kill 396 or kill -9 396 if 396 is the PID to be terminated. A killall foo kills all processes named foo . The -9 or -KILL signals indicate the severity of the action you wish to take: -1 is a gentle request, whereas -9 is termination with extreme prejudice. Do a man 7 signal for more details on signals.
2.2.4 PATH and Environment
When a Unix command, such as ls , is executed, how does Unix know where to find the ls program? An environment variable is set, called the PATH , which defines where things are looked for first. Execute the command printenv from a terminal shell. You'll see many environment variables , one of which is the PATH , and in that variable you should see something like /usr /local /bin: /usr /bin: /bin: /usr /bin /X11 .  This says that Unix first looks in /usr/local/bin , then in /usr/bin , then in /bin , then in /usr/bin/X11 for any program or command you want to execute, if you don't specify the direct path. It executes the first one it finds, so two programs of the same name could exist in different directories, and Unix would always execute the first one found in the order of the path unless explicitly told to go the other. You can alter the PATH , but the installer probably gave you an excellent beginning one, so leave it alone until you are sure you have a reason to change it.
Environment variables tell many different programs where to look to find things. For instance, what is the default editor (the variable EDITOR will tell you), where is the mail spool ( MAIL ), what is the default shell ( SHELL ), and so on? For an example of a few environment variables displayed in a shell, see Figure 2.2.
Figure 2.2. Environment variables
Next we provide a short introduction to commands we use in this book, and we leave you to man to find out more about them. Raising your awareness is all we can achieve here. Also, be aware that any problem you've had, any trick you seek to accomplish has probably been tried by someone else. USAH, UPT, and/or Google can ease your efforts.
There are a few commands that we have aliased with various options in our .bashrc permanently, and you might find them useful also. For example:
alias ls=ls -F --color=auto
This modifies the default nature of ls by adding some helpful information to the typical list, by using markers ( -F ) and colors in the directory listings (if you have a color xterm , links, directories, devices, etc., will all have different colors). In bash , all command-line arguments to the command are passed along automatically to the alias. If you simply type ls , you get ls -F --color . But if you type ls -a -B foo*.*bar* , the qualifiers and wildcards are passed into the alias for the plain ls to use as usual, in addition to the -F --color switches already defined.
Here are a few other useful aliases for ls :
alias ll=ls -l --color=auto alias l.=ls -d .[a-zA-Z0-9]* --color=auto
The first alias shortens the directory in long format (show file permissions, owner, size, date, etc.) to ll . The second displays all files, including hidden files that begin with the period character, shows directories as entries (instead of contents) and uses color markup.
Other useful Unix staples include sed and awk , which allow one to do such useful things as replace all the occurrences of a string within many files with another string. They are much more powerful than this, but that's a start.
2.2.6 Basic Filesystem Essentials
For a complete explanation of where things go and why they go there, see www.pathname.com/fhs/. Here we give a brief list of directories that you'll probably visit and what they are. The various versions of Unix each do things slightly differently, so there are no hard-and-fast rules. By the way, looking in all these directories to see what's there is an excellent learning exercise.
2.2.7 Useful Programs
Here is a list of Linux programs that we find extremely useful. A good place to find these sorts of things is freshmeat .net. For RPM-based distributions, another good site is rpmfind .net. Some of these programs are included with Red Hat and some are not.
If you need to change your configuration after installation (and you will), Red Hat includes GUI configuration programs that save the budding system administrator from having to edit text files by hand. Among these are the following: