📄 132-134.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=132-134//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="130-132.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="134-136.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P>To view the contents of a file, you can again use the <TT><B>more</B></TT> command. Just specify the name of the file you want to look at. In this case, type <TT><B>more output</B></TT>.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>Warning: </B><BR>Be careful! When you use <TT><B>></B></TT>, you completely overwrite the previous contents of the file from which you specify to take the output (if that file existed). For example, if we already have a file called <TT><B>output</B></TT> in our directory, its old contents will be completely replaced by the output from <TT><B>ls -l /bin</B></TT>. Linux <I>will not</I> warn you that you are about to do this!
<P>Be particularly careful if you’re not in your usual directory or if you’re logged in as <TT><B>root</B></TT>. You could, for instance, accidentally clobber a Linux program by mistake. It’s a good idea to check whether the output file already exists before using <TT><B>></B></TT>. In our example, we could have typed <TT><B>ls -l output</B></TT> beforehand. If no information is displayed, the file does not exist.<HR></FONT>
</BLOCKQUOTE>
</P>
<P>You can specify that you want to add your output to the end of the file, rather than replace the file’s contents, by using <TT><B>>></B></TT>. Type <TT><B>who >> output</B></TT> to add the output of the <TT><B>who</B></TT> command to the end of the text already in the file <TT><B>output</B></TT>.</P>
<P>You can examine the results by using either <TT><B>more</B></TT> or <TT><B>less</B></TT> and paging through to the end of the file or by using the Linux command <TT><B>tail</B></TT>, which displays the last few lines of the specified file. In this case, type <TT><B>tail output</B></TT> to see the last few lines of the file <TT><B>output</B></TT>. Try using <TT><B>tail</B></TT>!</P>
<H3><A NAME="Heading6"></A><FONT COLOR="#000077">Notational Conventions Used to Describe Linux Commands</FONT></H3>
<P>There is a set of accepted notational conventions used to describe, in a concise and consistent way, the correct syntax for any given Linux command. This specifies what options or parameters you must use, what options or parameters you can or cannot use, and so on. Sometimes this set of conventions is used to give a complete and exhaustive listing of a command’s syntax, showing every possible command and parameter. Sometimes it is used to make a particular example more general and the command’s basic usage clearer. You’ll run into these notations in manuals, man pages, and other sources of information.
</P>
<P>If you remember the following five basic rules, you will be able, in principle, to understand the syntax of any Linux or UNIX command.</P>
<H4 ALIGN="LEFT"><A NAME="Heading7"></A><FONT COLOR="#000077">Six Basic Rules of Linux Notation</FONT></H4>
<DL>
<DD><B>1.</B> Any text standing by itself, and not within <TT><B>[]</B></TT>, <TT><B><></B></TT>, or <TT><B>{}</B></TT>, must be typed exactly as shown.
<DD><B>2.</B> Any text within square brackets (<TT><B>[]</B></TT>) is optional. You can type it or not type it. For instance, the syntax <TT><B>ls [-l]</B></TT> means you must type <TT><B>ls</B></TT> (per the first rule), while adding <TT><B>-l</B></TT> is optional but not necessary. Do not type the square brackets themselves! In our example, type <TT><B>ls</B></TT> or <TT><B>ls -l</B></TT>. Do not type <TT><B>ls [-l]</B></TT> .
<DD><B>3.</B> Angle brackets (<TT><B><></B></TT>) and the text within them must be replaced by appropriate text (usually a name or value). The text within the brackets usually indicates the nature of the replacement. For instance, the syntax <TT><B>more</B> <<I>filename</I>></TT> means that you should replace <<I>filename</I>></B> with the name of the file you want to examine using <TT><B>more</B></TT>. If you want to look at the file <TT><B>output</B></TT>, type <TT><B>more output</B></TT>. Remember, do not use the angle brackets when you actually type the command!
<DD><B>4.</B> Curly braces (<TT><B>{}</B></TT>) indicate that you must choose one of the values given within the braces. The values are separated by <TT><B>|</B></TT> (which in this case means <I>or</I>, not <I>pipe!</I>). For example, the syntax <TT><B>command -{a|b}</B></TT> means you must enter either <TT><B>command -a</B></TT> or <TT><B>command -b</B></TT>.
<DD><B>5.</B> An ellipsis (<TT><B>…</B></TT>) means “and so on.” They are normally used with parameters such as filenames, which is described later.
<DD><B>6.</B> The sixth basic rule states that the brackets can be combined as necessary. For instance, you don’t have to type a filename with the <TT><B>more</B></TT> command which would be indicated as <TT><B>more [</B></TT><<I>filename</I>><TT><B>]</B></TT>. The outer set of square brackets makes the entire parameter optional. If you do decide to use the parameter, replace the inner set of angle brackets with the appropriate value. Because the <TT><B>more</B></TT> command enables one or more filenames to be specified, the syntax becomes <TT><B>more [</B><<I>filename</I>> <B>…]</B></TT>. The ellipsis means you can have as many <TT><B><</B><I>filenames</I><B>></B></TT> as you want, such as <TT><B>more output1 output2 output3</B></TT>.
</DL>
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="130-132.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="134-136.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 + -