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

📄 215-218.html

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTML
字号:
<HTML>

<HEAD>

<TITLE>Linux Configuration and Installation:Basic Linux Tools</TITLE>

<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
        var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>

 -->




<!--ISBN=1558285660//-->

<!--TITLE=Linux Configuration and Installation//-->

<!--AUTHOR=Patrick Volkerding//-->

<!--AUTHOR=Kevin Reichard//-->

<!--AUTHOR=Eric Foster//-->

<!--PUBLISHER=IDG Books Worldwide, Inc.//-->

<!--IMPRINT=M & T Books//-->

<!--CHAPTER=4//-->

<!--PAGES=215-218//-->

<!--UNASSIGNED1//-->

<!--UNASSIGNED2//-->



<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="212-215.html">Previous</A></TD>

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

<TD><A HREF="218-221.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>

<P><BR></P>

<H3><A NAME="Heading15"></A><FONT COLOR="#000077">Listing Files and Directories with Ls and Dir</FONT></H3>

<P>You&#146;ll use the <B>ls</B> command, short for <I>list</I>, quite often&#151;probably every time you use Linux, as a matter of fact. You&#146;ve already used <B>ls</B> in a discussion of permissions. The following command lists the contents of the current directory or a specified directory:</P>

<!-- CODE SNIP //-->

<PRE>

     gilbert:/$ ls

     bin/         dev/     home/          mnt/          sbin/     var/

     boot/        dos/     lib/           proc/         tmp/      vmlinuz

     cdrom/       etc/     lost&#43;found     root/         usr/

</PRE>

<!-- END CODE SNIP //-->

<P>If you&#146;re a UNIX user, this is probably not the version of <B>ls</B> you&#146;re used to, especially if you try this command on your own Linux box. The <B>ls</B> version contained with Linux is actually the GNU version of <B>ls</B>. As such, it makes several improvements to the basic <B>ls</B> command found on other versions of UNIX. One improvement, which we can&#146;t show you in the confines of a black-and-white text, is the addition of color to indicate directories (which will appear on your color monitor as blue) and special types of files. (Later in this section we&#146;ll explain how to change these colors and what the colors mean.) Linux also uses slashes after the name to indicate directories.</P>

<P>In addition, <B>ls</B> (by default) sorts files and directories in ASCII order, in columns. That&#146;s why the first column contains the directories beginning with <I>b</I> and <I>c</I>, followed by the rest of the alphabet. If there were directories that began with any capital letter, they&#146;d be listed first; the directory <B>X/</B> would appear before <B>bin/</B>, because under ASCII uppercase letters precede lowercase letters.</P>

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>NOTE:&nbsp;&nbsp;</B>The Bourne Again SHell, <B>bash</B>, also supports the <B>dir</B> command in a limited sense. The <B>dir</B> command does the same thing as the <B>ls -l</B> command, which will be explained later in this section. DOS users will be relieved to know that their familiar <B>dir</B> command can also be used under Linux.<HR></FONT>

</BLOCKQUOTE>

<P>You can use one of the many command-line options to the <B>ls</B> command. For example, if you use the <B>ls</B> command in your home directory, you&#146;ll discover that there are no apparent files to be found:</P>

<!-- CODE SNIP //-->

<PRE>

     gilbert:~$ ls

     gilbert:~$

</PRE>

<!-- END CODE SNIP //-->

<P>However, if you run the command with the <I>-a</I> option, you&#146;ll see the following:</P>

<!-- CODE SNIP //-->

<PRE>

     gilbert:~$ ls -a

     ./      .bash_history     .kermrc        .lessrc

     ../     .emacs            .less          .term/

</PRE>

<!-- END CODE SNIP //-->

<P>The files beginning with the period (<B>.</B>) are called <I>hidden</I> files. Actually, they&#146;re not so hidden as to be mysterious; they&#146;re merely hidden when you use the <B>ls</B> command to search for files. The <I>-a</I> option tells the <B>ls</B> command to look for <I>all</I> files.</P>

<P>There are two other listings&#151;<B>.</B> and <B>..</B>&#151;that may be unfamiliar if you&#146;re not a UNIX user. The single period (<B>.</B>) is merely another way to display the current directory, while the double period (<B>..</B>) is used to display the parent directory.</P>

<P>The <I>-l</I> (ell, not one) option to <B>ls</B> prints a long list of the directory&#146;s contents:</P>

<!-- CODE SNIP //-->

<PRE>

     gilbert:~$ ls -l

</PRE>

<!-- END CODE SNIP //-->

<P>The <B>ls</B> command can also be used to determine the existence of a single file in short form:</P>

<!-- CODE SNIP //-->

<PRE>

     gilbert:~$ ls data

     data

</PRE>

<!-- END CODE SNIP //-->

<P>or in long form:

</P>

<!-- CODE SNIP //-->

<PRE>

     gilbert:~$ ls -l data

     -rwx------  1 kevinr  group1     854 Apr  2 19:12 data

</PRE>

<!-- END CODE SNIP //-->

<P>Table 4.5 summarizes the <B>ls</B> command&#146;s important options.</P>

<CENTER>

<TABLE WIDTH="95%"><CAPTION><B>Table 4.5</B> A Summary of the Ls Command Options

<TR>

<TH WIDTH="25%" ALIGN="LEFT">Option

<TH WIDTH="75%" ALIGN="LEFT">Result

<TR>

<TH COLSPAN="2"><HR>

<TR>

<TD>-a

<TD>Lists all files, including hidden files.

<TR>

<TD>-A

<TD>Lists all files, except for the . and .. listings.

<TR>

<TD VALIGN="TOP">-c

<TD>Sorts files by the time they were last changed, rather than by the default ASCII order, beginning with the oldest file.

<TR>

<TD>-d

<TD>Lists only the name of a directory, not its contents.

<TR>

<TD>-l

<TD>Lists files and directories in long format.

<TR>

<TD>-r

<TD>Lists the contents in reverse order.

<TR>

<TD VALIGN="TOP">-t

<TD>Sorts files by the time they were last changed beginning with the newest file.

<TR>

<TD VALIGN="TOP">-x

<TD>Lists files and sorts them across the page instead of by columns.

<TR>

<TD COLSPAN="2"><HR>

</TABLE>

</CENTER>

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>NOTE:&nbsp;&nbsp;</B>The <B>ls</B> command isn&#146;t the only tool for viewing files and directories on a Linux system. If you&#146;ve installed XFree86, there&#146;s a file manager that can be used to graphically display the contents of your Linux system (see Chapter 5 for details). And there&#146;s a command-line tool, the Midnight Commander, that works similarly to the Norton Commander (a once-popular MS-DOS application) (see Chapter 5 for details).<HR></FONT>

</BLOCKQUOTE>

<P><FONT SIZE="+1"><B>Changing the Ls Colors</B></FONT></P>

<P>Although we can&#146;t show you, <B>ls</B> does indeed display different types of files in different colors. While you probably don&#146;t want to change these colors, Linux gives you the ability to do so. (Indeed, Linux gives you the ability to do a great many things you&#146;ll probably never bother to do, but that&#146;s to the credit of the people who put Linux together.) The settings for these colors are stored in the file <B>/etc/DIR_COLORS</B>, and this file is used by all users. If you want to change these settings, you need to copy this file to your home directory, rename the file <B>.dir_colors</B> (making it a hidden file), and edit the listings in the file. As with many of the configuration files used with Linux, there&#146;s enough comments in the default <B>/etc/DIR_COLORS</B> to guide you through any editing session.</P><P><BR></P>

<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="212-215.html">Previous</A></TD>

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

<TD><A HREF="218-221.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 + -