📄 128-130.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=128-130//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="125-128.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="130-132.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P>You now get a listing with many more details about the files. (These will be explained in Chapter 8, “Using the File System.”) The <TT><B>l</B></TT> option can be used by itself; <TT><B>ls -l</B></TT> gives detailed descriptions of files that don’t begin with a period. Sometimes filenames are so long they don’t fit on a single line; Linux simply wraps the remainder to the next line.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>Note: </B><BR>Strictly speaking, the hyphen (<TT><B>-</B></TT>) is not part of the command option. The hyphen simply tells Linux to understand each letter immediately following it as a command option. There <I>must</I> be a space before the hyphen, and there <I>must not</I> be a space between the hyphen and the letter or letters making up the command option. There <I>must</I> be a space after the command option if anything else is to be entered on the command line after it.
<P>You can type more than one command option after the hyphen, as we did with <TT><B>ls -al</B></TT>. In this case, we are specifying both the <TT><B>a</B></TT> and the <TT><B>l</B></TT> options. The order in which you specify options usually doesn’t matter; <TT><B>ls -al</B></TT> gives the same results as <TT><B>ls -la</B></TT>. Combining options doesn’t work with all Linux commands; it works only with those that use a single letter to specify each option.</P>
<P>Multiple options can also be specified individually, with each option preceded by a hyphen and separated from other options by spaces—for example, <TT><B>ls -a -l</B></TT>. This is usually done only when a particular option requires a further parameter.<HR></FONT>
</BLOCKQUOTE>
</P>
<P>By default, <TT><B>ls</B></TT> lists files in alphabetical order. Sometimes you may be more interested in when a file was created or last modified. The <TT><B>t</B></TT> option tells <TT><B>ls</B></TT> to sort files by date instead of alphabetically by filename, showing the newest files first. Therefore, when you enter <TT><B>ls -alt</B></TT>, you see the following:</P>
<!-- CODE //-->
<PRE>
darkstar:~$ <TT><B>ls -alt</B></TT>
total 10
drwxr-xr-x 3 fido users 1024 Jan 2 13:48 ./
-rw-r--r-- 1 fido users 333 Dec 21 22:11 .bash_history
drwxr-xr-x 6 root root 1024 Dec 14 01:39 ../
-rw-r--r-- 1 fido users 163 Dec 7 14:31 .kermrc
drwxr-xr-x 2 fido users 1024 Dec 7 13:36 .term/
-rw-r--r-- 1 fido users 3016 May 13 1994 .emacs
-rw-r--r-- 1 fido users 114 Nov 23 1993 .lessrc
-rw-r--r-- 1 fido users 34 Jun 6 1993 .less
</PRE>
<!-- END CODE //-->
<P>The <TT><B>r</B></TT> option tells <TT><B>ls</B></TT> to produce a reverse output. This is often used with the <TT><B>t</B></TT> option. The following is an example of what displays when you enter <TT><B>ls -altr</B></TT>:</P>
<!-- CODE //-->
<PRE>
darkstar:~$ <TT><B>ls -altr</B></TT>
total 10
-rw-r--r-- 1 fido users 34 Jun 6 1993 .less
-rw-r--r-- 1 fido users 114 Nov 23 1993 .lessrc
-rw-r--r-- 1 fido users 3016 May 13 1994 .emacs
drwxr-xr-x 2 fido users 1024 Dec 7 13:36 .term/
-rw-r--r-- 1 fido users 163 Dec 7 14:31 .kermrc
drwxr-xr-x 6 root root 1024 Dec 14 01:39 ../
-rw-r--r-- 1 fido users 333 Dec 21 22:11 .bash_history
drwxr-xr-x 3 fido users 1024 Jan 2 13:48 ./
</PRE>
<!-- END CODE //-->
<P>Many other options can be used with <TT><B>ls</B></TT>, although you have just worked with the most commonly used ones. The important thing to remember is that you can usually customize a Linux command by using one or more command options.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>Note: </B><BR>With the basic Linux commands, case is important! For instance, <TT><B>ls</B></TT> has an <TT><B>R</B></TT> option (<I>recursive:</I> show files in subdirectories, too) which gives much different results from the <TT><B>r</B></TT> option.<HR></FONT>
</BLOCKQUOTE>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>Tip: </B><BR>You can think of <TT><B>a</B></TT> as the “all files” option, <TT><B>l</B></TT> as the “long list” option, <TT><B>t</B></TT> as the “sort by time” option, <TT><B>r</B></TT> as the “reverse sort” option, and so on. In fact, most options in Linux are <I>mnemonic</I>—the option letter stands for a word or phrase. Some option letters mean the same thing in many different Linux commands. For instance, <TT><B>v</B></TT> often means <I>verbose</I>—in other words, “Give me lots of detail.”
<P>However, do not assume that on an unfamiliar command certain options will work in the “usual” way! For instance, <TT><B>r</B></TT> is the recursive option for many Linux commands; however, in the case of <TT><B>ls</B></TT>, reverse sort is more commonly used, and therefore it gets the easier-to-type lowercase <I>r</I>, while recursive is left with the capital <I>R</I>. It might seem like not much extra effort to press the Shift key to get the capital letter, but try typing a string of four or five options, one of which is capitalized!<HR></FONT>
</BLOCKQUOTE>
</P>
<H4 ALIGN="LEFT"><A NAME="Heading4"></A><FONT COLOR="#000077">Other Parameters</FONT></H4>
<P>Linux commands often use parameters that are not actual command options. These parameters, such as filenames or directories, are <I>not</I> preceded by a hyphen.</P>
<P>For instance, by default <TT><B>ls</B></TT> lists the files in your current directory. You can, however, tell <TT><B>ls</B></TT> to list the files in any other directory simply by adding the directory to the command line. For instance, <TT><B>ls /bin</B></TT> lists everything in the <TT><B>/bin</B></TT> directory. This can be combined with command options, so that <TT><B>ls -l /bin</B></TT> gives you detailed listings of the files in <TT><B>/bin</B></TT>. Try this. You will be impressed by the number of files in the <TT><B>/bin</B></TT> directory!</P>
<P>You can also specify <TT><B>ls</B></TT> to list information about any particular file by entering its filename. For instance, <TT><B>ls -la .lessrc</B></TT> displays detailed information only about the <TT><B>.lessrc</B></TT> file. If the file doesn’t exist, Linux doesn’t show anything.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="125-128.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="130-132.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 + -