📄 145-148.html
字号:
<HTML>
<HEAD>
<TITLE>Linux Unleashed, Third Edition:Basic Linux Commands</TITLE>
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!--ISBN=0672313723//-->
<!--TITLE=Linux Unleashed, Third Edition//-->
<!--AUTHOR=Tim Parker//-->
<!--PUBLISHER=Macmillan Computer Publishing//-->
<!--IMPRINT=Sams//-->
<!--CHAPTER=7//-->
<!--PAGES=145-148//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="143-145.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="../ch08/149-152.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H3><A NAME="Heading17"></A><FONT COLOR="#000077">Becoming Someone Else: The su Command</FONT></H3>
<P>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.
</P>
<P>In these cases, you can use the <TT><B>su</B></TT> command. “su” stands for “super user.” If you type <TT><B>su</B></TT> by itself, you will be prompted for the <TT><B>root</B></TT> password. If you successfully enter the <TT><B>root</B></TT> password, you will see the <TT><B>root</B></TT> <TT><B>#</B></TT> prompt and have all of <TT><B>root</B></TT>’s privileges.</P>
<P>You can also become any other user by typing <TT><B>su</B></TT> <I><username></I>. If you are <TT><B>root</B></TT> when you type <TT><B>su</B></TT> <I><username></I>, 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 <TT><B>root</B></TT> 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.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>Note: </B><BR>Although <TT><B>su</B></TT> 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 <TT><B>su</B></TT> is not really suited to doing extended work, and it’s quite unsuitable for troubleshooting problems with that login.<HR></FONT>
</BLOCKQUOTE>
<H3><A NAME="Heading18"></A><FONT COLOR="#000077">The grep Command</FONT></H3>
<P>“What on earth does <TT><B>grep</B></TT> mean?” you ask. This is a fair question. <TT><B>grep</B></TT> must be the quintessential UNIX acronym because it’s impossible to understand even when it’s spelled out in full! <TT><B>grep</B></TT> stands for <I>Global Regular Expression Parser</I>. 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.</P>
<P>What <TT><B>grep</B></TT> 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.</P>
<P>There are two basic ways to use <TT><B>grep</B></TT>. The first use of <TT><B>grep</B></TT> is to filter the output of other commands. The general syntax is <TT><<I>command</I>> <B>| grep</B> <<I>pattern</I>></TT>. For instance, if you want to see every actively running process on the system, type <TT><B>ps -a | grep R</B></TT>. In this application, <TT><B>grep</B></TT> 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 <TT><B>Resting</B></TT>, it would show up even if its status were <TT><B>S</B></TT> for sleeping because <TT><B>grep</B></TT> would match the R in <TT><B>Resting</B></TT>. An easy way around this problem is to type <TT><B>grep “R”</B></TT>, which explicitly tells <TT><B>grep</B></TT> 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.</P>
<P>The second use of <TT><B>grep</B></TT> is to search for lines that contain a specified pattern in a specified file. The syntax here is <TT><B>grep</B> <<I>pattern</I>> <<I>filename</I>></TT>. 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.</P>
<H3><A NAME="Heading19"></A><FONT COLOR="#000077">Summary</FONT></H3>
<P>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.
</P>
<P>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: <TT><B>login</B></TT>, <TT><B>passwd</B></TT>, <TT><B>who</B></TT>, <TT><B>adduser</B></TT>, 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!</P>
<P>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.</P>
<P>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:</P>
<DL>
<DD>Working with the editors that come with Linux is discussed in Chapter 16, “Text Editors: <TT>vi</TT> and <TT>emacs</TT>.”
<DD>Configuring X so you can use a GUI is discussed in Chapter 22, “Installing and Configuring XFree86.”
<DD>Programming under Linux is discussed in Part V, starting with Chapter 25, “<TT>gawk</TT>.”
</DL>
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="143-145.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="../ch08/149-152.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -