⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 130-132.html

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 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=130-132//-->

<!--UNASSIGNED1//-->

<!--UNASSIGNED2//-->



<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="128-130.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="132-134.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>

<P><BR></P>

<H4 ALIGN="LEFT"><A NAME="Heading5"></A><FONT COLOR="#000077">Input and Output Redirection</FONT></H4>

<P>Many Linux commands let you specify which file or directory they are to act upon, as we saw earlier with the example <TT><B>ls -l /bin</B></TT>.</P>

<P>You can also &#147;pipe&#148; the output from a command so that it becomes another command&#146;s input. This is done by typing two or more commands separated by the <TT><B>|</B></TT> character. (This character normally is found on the same key as the <TT><B>\</B></TT> character. You must hold the Shift key or you get <TT><B>\</B></TT> instead of <TT><B>|</B></TT>). The <TT><B>|</B></TT> character means &#147;Use the output from the previous command as the input for the next command.&#148; Therefore, typing <TT><B>command_1|command_2</B></TT> does both commands, one after the other, before giving you the results.</P>

<P>Using our assembly-line metaphor, items are being processed through two black boxes instead of just one. When we use piping, it&#146;s like hooking up the first command&#146;s output conveyor belt to become the input conveyor belt for the second command.</P>

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>Tip:&nbsp;&nbsp;</B><BR>Although Linux doesn&#146;t care whether <TT><B>|</B></TT> is set off by spaces, if <TT><B>command_1 | command_2</B></TT> is easier for you to read and understand than <TT><B>command_1|command_2</B></TT>, by all means use spaces around <TT><B>|</B></TT>.<HR></FONT>

</BLOCKQUOTE>

<P>You may have noticed that the output of <TT><B>ls -l /bin</B></TT> is many lines long, so that much of the information scrolls off the screen before you can read it. You can pipe this output to a formatting program called <TT><B>more</B></TT>, which displays information in screen-sized chunks. When you enter <TT><B>ls -l /bin | more</B></TT>, you see the following:</P>

<!-- CODE //-->

<PRE>

darkstar:~&#36; <TT><B>ls -l /bin | more</B></TT>

total 1611

-rwxr-xr-x  1 root   bin      1248 Sep 17 04:25 arch*

-rwxr-xr-x  1 root   bin    295940 Sep  5 01:45 bash*

-rwxr-xr-x  1 root   bin      4840 Nov 24 1993  cat*

-rwxr-xr-x  1 root   bin      9220 Jul 20 12:06 chgrp*

-rwxr-xr-x  1 root   bin     13316 Jul 20 12:06 chmod*

-rwxr-xr-x  1 root   bin     13316 Jul 20 12:06 chown*

lrwxrwxrwx  1 root   root       17 Dec  7 13:37 compress -&gt; /usr/bin/comp

ress*

-rwxr-xr-x  1 root   bin     21508 Jul 20 12:06 cp*

-rwxr-xr-x  1 root   bin     41988 May  1 1994  cpio*

lrwxrwxrwx  1 root   root        4 Dec  7 13:40 csh -&gt; tcsh*

-rwxr-xr-x  1 root   bin      5192 Nov 24 1993  cut*

-rwxr-xr-x  1 root   bin     19872 Mar 23 1994  date*

-rwxr-xr-x  1 root   bin     17412 Jul 20 12:06 dd*

-rwxr-xr-x  1 root   bin     13316 Jul 20 12:06 df*

-rwxr-xr-x  1 root   bin     66564 Jun  9  1994 dialog*

-rwxr-xr-x  1 root   bin     1752  Sep 17 04:25 dmesg*

lrwxrwxrwx  1 root   root       8  Dec  7 13:37 dnsdomainname -&gt; hostname

*

-rwxr-xr-x  1 root   bin     13316 Jul 20 12:06 du*

-rwxr-xr-x  1 root   bin      3312 Mar 23  1994 echo*

-rwxr-xr-x  1 root   bin     36684 May  4  1994 ed*

-rwxr-xr-x  1 root   bin       326 Mar 23  1994 false*

<TT><B>--More--</B></TT>

</PRE>

<!-- END CODE //-->

<P>The <TT><B>--More--</B></TT> at the bottom of the screen tells you that there&#146;s more text to come. To go to the next screen of text, press the Spacebar. Every time you press the Spacebar, <TT><B>more</B></TT> displays another screen full of text. When the last screen with text has been displayed, <TT><B>more</B></TT> returns you to the Linux prompt.</P>

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>Tip:&nbsp;&nbsp;</B><BR>The <TT><B>more</B></TT> command can do many other things. For instance, to move back one screen at a time, press <TT><B>b</B></TT> for &#147;back.&#148; (Not all versions of <TT><B>more</B></TT> support the <TT><B>b</B></TT> option.) Another useful command is <TT><B>q</B></TT> for &#147;quit.&#148; This lets you leave immediately, without having to go through all the remaining screens of text. Ctrl&#43;C does the same thing.

<P>While in <TT><B>more</B></TT>, press <TT><B>h</B></TT> for &#147;help.&#148; This lists the commands available within <TT><B>more</B></TT>.<HR></FONT>

</BLOCKQUOTE>

</P>

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>Note:&nbsp;&nbsp;</B><BR>Linux sometimes includes the command <TT><B>less</B></TT> instead of <TT><B>more</B></TT>. One difference you will notice is that, unlike <TT><B>more</B></TT>, <TT><B>less</B></TT> requires you to type <TT><B>q</B></TT> to return to the command line, even if you&#146;re at the end of the text to be displayed. This may seem cumbersome, but it prevents you from accidentally exiting the program by pressing the Spacebar once too often.

<P>The name <TT><B>less</B></TT> is a play on <TT><B>more</B></TT>. Originally, <TT><B>less</B></TT> was designed to have many features that <TT><B>more</B></TT> lacked. The version of <TT><B>more</B></TT> included in most Linux system has most of these features, however.</P>

<P>The Linux <TT><B>man</B></TT> program, discussed later, uses <TT><B>less</B></TT> to display text. Most other UNIX systems use <TT><B>more</B></TT> by default. Don&#146;t get confused. Just remember to press <TT><B>q</B></TT> to exit from <TT><B>less</B></TT>!<HR></FONT>

</BLOCKQUOTE>

</P>

<P>Another thing you can do in Linux is send output to a file instead of the screen. There are many different reasons why you might want to do this. Perhaps you want to save a &#147;snapshot&#148; of a command&#146;s output as it was at a certain time or maybe you want to save a command&#146;s output for further examination. You might also want to save the output from a command that takes a very long time to run, and so on.</P>

<P>To send output to a file, use the <TT><B>&gt;</B></TT> symbol (found above the period on your keyboard). For instance, you can place the output of the <TT><B>ls -l /bin</B></TT> command into a file called <TT><B>output</B></TT> by typing <TT><B>ls -l /bin &gt; output</B></TT>. Again, spaces around <TT><B>&gt;</B></TT> are optional and not strictly necessary, but they do make the command much more readable.</P>

<P>If you now enter an <TT><B>ls</B></TT> or <TT><B>ls -l command</B></TT>, you will see that you&#146;ve created a new file called <TT><B>output</B></TT> in your own directory.</P><P><BR></P>

<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="128-130.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="132-134.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 + -