-->
Previous | Table of Contents | Next |
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 youre 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 youre in a situation (such as logged on via a telephone and modem) in which you dont 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 roots 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 users password since in principle you could change the users password or examine all the users 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 wont inherit that logins exact environment or run that logins startup files (if any). This means that su is not really suited to doing extended work, and its quite unsuitable for troubleshooting problems with that login.
What on earth does grep mean? you ask. This is a fair question. grep must be the quintessential UNIX acronym because its impossible to understand even when its 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, its 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. Its 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.
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:
Previous | Table of Contents | Next |