📄 119-122.html
字号:
<HTML>
<HEAD>
<TITLE>Linux Unleashed, Third Edition:Getting Started</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=6//-->
<!--PAGES=119-122//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="117-119.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="122-124.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H3><A NAME="Heading10"></A><FONT COLOR="#000077">Trying Out Your New Login</FONT></H3>
<P>Now you can try out your new login. We can also look at some of the interesting features and capabilities of Linux.
</P>
<P>At the login prompt, type the login name you have just created. If you were conscientious and assigned a nonzero-length password to your new login, enter the password when prompted.</P>
<P>You should now see the following (or something similar to it):</P>
<!-- CODE SNIP //-->
<PRE>
darkstar login: <B>fido</B>
<B>Password:</B>
Last login: Sun Dec 11 19:14:22 on tty1
Linux 1.2.13 (POSIX).
Quiet! I hear a hacker….
darkstar:~$
</PRE>
<!-- END CODE SNIP //-->
<P>The messages for the most part are the same as when you logged in as <TT>root</TT>. Some systems don’t show you anything except the shell prompt, but you can change that. Note that your prompt looks different from the <TT>root</TT> prompt or the pound sign. The <TT>$</TT> prompt indicates that you are a regular user running under the <TT>bash</TT> shell (which was the default choice presented by the <TT>adduser</TT> program). Also, there is no <TT>You have mail</TT> message (because you have no mail).</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>Note: </B><BR>Linux can be configured to automatically mail a message to all new users. This can be a greeting or can give system information and etiquette.<HR></FONT>
</BLOCKQUOTE>
<P>To see an example of the difference between the <TT>root</TT> login and a regular user login, type <B>adduser</B> at the shell prompt and press Enter.</P>
<!-- CODE SNIP //-->
<PRE>
darkstar:~$ <B>adduser</B>
bash: adduser: command not found
</PRE>
<!-- END CODE SNIP //-->
<P>The message you get looks somewhat cryptic. However, it has a typical Linux error message structure, so it’s worth making a little effort now to understand it.
</P>
<H4 ALIGN="LEFT"><A NAME="Heading11"></A><FONT COLOR="#000077">Linux Error Messages</FONT></H4>
<P>First of all, in the error message shown previously there’s quite a bit of information. The program that is giving you the message is your shell, <TT>bash</TT>. It therefore announces itself with <TT>bash:</TT>, somewhat like the character in a play script. Next is the shell’s “monologue.” Being the “strong and silent” type of character, <TT>bash</TT>’s monologue is very terse and to the point. It declares the program that is causing problems (<TT>adduser</TT>) and the specific problem with this program: the command (<TT>adduser</TT>) can’t be found.</P>
<P>If the error message were expanded into real English, it would read something like this: “Hi, I’m <TT>bash</TT>. You know that <TT>adduser</TT> command you gave me? I looked everywhere for <TT>adduser</TT> but I couldn’t find it, so I couldn’t perform whatever actions <TT>adduser</TT> would have specified.” With time, you will get quite good at understanding Linux error message grammar.</P>
<H4 ALIGN="LEFT"><A NAME="Heading12"></A><FONT COLOR="#000077">Search Paths</FONT></H4>
<P>Why can <TT>root</TT> find <TT>adduser</TT>, but an ordinary user cannot? Linux has many directories, and each directory can hold many files (one of which can be the elusive <TT>adduser</TT>). In theory, Linux could go search through the entire file system until it found <TT>adduser</TT>. But if <TT>root</TT> accidentally mistyped <TT>adduser</TT> as <TT>aduser</TT>, Linux would have to rummage through every nook and cranny before finally giving up. This could take many seconds and cause needless wear and tear on your hard drive (not to mention drive you nuts while every file was searched every time you typed anything).</P>
<P>Therefore, Linux has <I>search paths</I> for finding commands (which we discuss in more detail in Chapter 8). Usually, only a small part of the entire Linux file system is on the search path along which Linux searches. Because <TT>root</TT> makes use of many system administration programs such as <TT>adduser</TT>, the directories that hold these programs are in <TT>root</TT>’s search path. Ordinary users do not have system administration directories in their search path.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>Tip: </B><BR>Linux search paths are very similar to those you may be aware of for DOS or Windows. The syntax for the paths and the way the directories are written are different but the approach is the same.<HR></FONT>
</BLOCKQUOTE>
<P>There is a way around this problem of not finding a file which is not in your search path, though. If you explicitly tell Linux where a file is located, then it doesn’t have to look through its search path. As it happens, <TT>adduser</TT> is found on most Linux systems in the <TT>/sbin</TT> directory. Try running <TT>/sbin/adduser</TT>.</P>
<!-- CODE SNIP //-->
<PRE>
darkstar:~$ /sbin/adduser
bash: /sbin/adduser: Permission denied
</PRE>
<!-- END CODE SNIP //-->
<P>This time, <TT>bash</TT> could find <TT>adduser</TT> (because you told it exactly where to look) but discovered that an ordinary user does not have permission to run <TT>adduser</TT>. As you can see, Linux limits the actions of logins to their privilege level and only root (at least at this point) can run <TT>adduser</TT>. (We’ll talk about privileges in Chapter 9.)</P>
<H3><A NAME="Heading13"></A><FONT COLOR="#000077">The who Command</FONT></H3>
<P>A very simple Linux command, which is also one of the most commonly used when you learn more about working with the shell and shell programming, is the <TT>who</TT> command. This simple command does one task: It shows you who is logged in at the moment. The <TT>who</TT> command is unusual in Linux because it takes no arguments. You use it by itself on the command line. Here’s a sample command and its output:</P>
<!-- CODE SNIP //-->
<PRE>
$ who
tparker tty02 May 18 18:29
root tty01 May 15 15:18
root tty03 May 15 15:17
bills ttyp0 May 18 18:29
ychow ttyp1 May 25 17:31
</PRE>
<!-- END CODE SNIP //-->
<P>The <TT>who</TT> command shows you three columns of information for each user that is on the system. First it shows the login that the user is employing. The second column shows the terminal the user is using (this is a device name, something we’ll look at in more detail in Chapter 33, “Devices”). The third column shows the time that the user logged in.</P>
<P>If a user is logged in on more than one terminal or virtual terminal (we’ll discuss virtual terminals in the next section), then each login is displayed. In the preceding output, you can see <TT>root</TT> is logged in twice on two different terminals.</P>
<P>The output of <TT>who</TT> is generated every time you run the command, so if a user logs off, the output from <TT>who</TT> is accurate from the moment you issue the command.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="117-119.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="122-124.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 + -