-->
Previous Table of Contents Next


Becoming Someone Else: The su Command

Usually, when you want to temporarily become a different user, you simply switch to another virtual terminal, log in as the other user, log out when you’re done, and return to your “home” virtual terminal. However, there are times when this is impractical or inconvenient. Perhaps all your virtual terminals are busy already, or perhaps you’re in a situation (such as logged on via a telephone and modem) in which you don’t have virtual terminals available.

In these cases, you can use the su command. “su” stands for “super user.” If you type su by itself, you will be prompted for the root password. If you successfully enter the root password, you will see the root # prompt and have all of root’s privileges.

You can also become any other user by typing su <username>. If you are root when you type su <username>, you are not asked for that user’s password since in principle you could change the user’s password or examine all the user’s files from the root login anyway. If you are an “ordinary” user trying to change to another ordinary user, you will be asked to enter the password of the user you are trying to become.


Note:  
Although su grants you all the privileges you would get if you logged on as that user, be aware that you won’t inherit that login’s exact environment or run that login’s startup files (if any). This means that su is not really suited to doing extended work, and it’s quite unsuitable for troubleshooting problems with that login.

The grep Command

“What on earth does grep mean?” you ask. This is a fair question. grep must be the quintessential UNIX acronym because it’s impossible to understand even when it’s spelled out in full! grep stands for Global Regular Expression Parser. You will understand the use of this command right away, but when “Global Regular Expression Parser” becomes a comfortable phrase in itself, you should probably consider taking a vacation.

What grep does, essentially, is find and display lines in a file that contain a pattern that you specify. In other words, it’s a tool that checks for substrings.

There are two basic ways to use grep. The first use of grep is to filter the output of other commands. The general syntax is <command> | grep <pattern>. For instance, if you want to see every actively running process on the system, type ps -a | grep R. In this application, grep passes on only those lines that contain the pattern (in this case, the single letter) R. Note that if someone were running a program called Resting, it would show up even if its status were S for sleeping because grep would match the R in Resting. An easy way around this problem is to type grep “R”, which explicitly tells grep to search for an R with a space on each side. You must use quotes whenever you search for a pattern that contains one or more blank spaces.

The second use of grep is to search for lines that contain a specified pattern in a specified file. The syntax here is grep <pattern> <filename>. Be careful. It’s easy to specify the filename first and the pattern second by mistake! Again, you should be as specific as you can with the pattern to be matched, in order to avoid “false” matches.

Summary

By this point, you should have tried enough different Linux commands to start getting familiar (if not yet entirely comfortable) with typical Linux usage conventions.

It is important that you be able to use the man pages provided online by Linux. A very good exercise at this point is to pull up man pages for all the commands we have looked at in the past two chapters: login, passwd, who, adduser, and so on. If any of the commands listed under “See also:” look interesting, by all means take a look at their man pages, too!

In Chapter 8, we head out from “home” and poke around in the Linux file system. As system administrators, we should know what our hard drives contain! For instance, there are special “administrator-only” directories crammed with goodies.

Several more “essential” commands are also introduced. By the end of the next chapter, you will have seen and tried most of the important “user” Linux commands and had a taste of some of the “administrator” commands. If you are interested in other related subjects, you can jump to the following chapters:

Working with the editors that come with Linux is discussed in Chapter 16, “Text Editors: vi and emacs.”
Configuring X so you can use a GUI is discussed in Chapter 22, “Installing and Configuring XFree86.”
Programming under Linux is discussed in Part V, starting with Chapter 25, “gawk.”


Previous Table of Contents Next