167-170.html

来自「linux-unix130.linux.and.unix.ebooks130 l」· HTML 代码 · 共 152 行

HTML
152
字号
<HTML>

<HEAD>

<TITLE>Linux Unleashed, Third Edition:Using the File System</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=8//-->

<!--PAGES=167-170//-->

<!--UNASSIGNED1//-->

<!--UNASSIGNED2//-->



<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="164-166.html">Previous</A></TD>

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

<TD><A HREF="170-172.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>

<P><BR></P>

<H4 ALIGN="LEFT"><A NAME="Heading22"></A><FONT COLOR="#000077">Removing Directories</FONT></H4>

<P>The <TT><B>rm</B></TT> command works primarily with files. If you try to delete a directory with <TT><B>rm</B></TT>, an error message displays. The command normally used to remove (delete) directories is <TT><B>rmdir</B></TT>. The syntax is <B>rmdir</B> &lt;<I>directory</I>&gt;</TT>.</P>

<P>Before you can remove a directory, it must be empty (the directory can&#146;t hold any files or subdirectories). Otherwise, you see</P>

<!-- CODE SNIP //-->

<PRE>

rmdir: &lt;<I>directory</I>&gt;: Directory not empty

</PRE>

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

<P>This is as close to a safety feature as you will see in Linux!

</P>

<P>This one might baffle you:</P>

<!-- CODE //-->

<PRE>

darkstar:/home&#36; ls

fido/    root/     zippy/

darkstar:/home&#36; ls zippy

core      kazoo     stuff

darkstar:/home&#36; rm zippy/*

darkstar:/home/zippy&#36; ls zippy

darkstar:/home&#36; rmdir zippy

rmdir: zippy: Directory not empty

darkstar:~&#36;

</PRE>

<!-- END CODE //-->

<P>The reason for the <TT><B>Directory not empty</B></TT> message is that files starting with <B>.</B> are usually special system files that are usually hidden from the user. To list files whose names start with ., you have to use <TT><B>ls -a</B></TT>. To delete these files, use <B>rm .*</B>:</P>

<!-- CODE //-->

<PRE>

darkstar:/home&#36; <B>ls -a zippy</B>

./   ../   .bashrc       .profile

darkstar:/home&#36; <B>rm zippy/.*</B>

rm: cannot remove &#145;.&#146; or &#145;..&#146;

darkstar:/home&#36; <B>ls -a zippy</B>

./  ../

darkstar:/home&#36; <B>rmdir zippy</B>

darkstar:/home&#36; <B>ls</B>

fido/  root/

darkstar:~&#36;

</PRE>

<!-- END CODE //-->

<P>You will most often come across this situation in a system administrator role.

</P>

<P>Sometimes you want to remove a directory with many layers of subdirectories. Emptying and then deleting all the subdirectories one by one is very tedious. Linux offers a way to remove a directory and all the files and subdirectories it contains in one easy step. This is the <TT><B>r</B></TT> (recursive) option of the <TT><B>rm</B></TT> command. The syntax is <TT><B>rm -r</B> &lt;<I>directory</I>&gt;</TT>. The directory and all its contents are removed.</P>

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>Warning:&nbsp;&nbsp;</B><BR>You should use <TT>rm -r</TT> only when you absolutely have to. To paraphrase an old saying, &#147;It&#146;s only a shortcut until you make a mistake.&#148; For example, if you&#146;re logged in as <TT>root</TT>, the following command removes all files from your hard disk, and then it&#146;s &#147;Hello, installation procedure&#148; time (do <I>not</I> type the following command!):

<!-- CODE SNIP //-->

<PRE>

rm -r /

</PRE>

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

<P>Believe it or not, people do this all too often. Don&#146;t join the club!<HR></FONT>

</BLOCKQUOTE>

</P>

<H4 ALIGN="LEFT"><A NAME="Heading23"></A><FONT COLOR="#000077">Fear of Compression: The Zipless File</FONT></H4>

<P>Most Linux files are stored on the installation CD-ROM in compressed form. This allows more information to be stored. If you work with DOS or Windows, you may have seen utilities that ZIP files into a larger library. Utilities such as PKZIP and WINZIP are very popular in those operating systems. The same type of technique has been used by UNIX for decades, although a different name and compression technique are used.

</P>

<P>When you install Linux, the installation program uncompresses many of the files it transfers to your hard drive. However, if you look, you will be able to find compressed files!</P>

<P>Any file ending in .gz&#151;for example, <TT><B>squashed.gz</B></TT>&#151;is a compressed file. To uncompress this particular type of file, type <TT><B>gunzip</B> &lt;<I>file</I>&gt;</TT>. For this example, type <TT><B>gunzip squashed.gz</B></TT>. The <TT><B>gunzip</B></TT> program creates an uncompressed file and removes the .gz extension. Therefore, you wind up with a normal file called <TT><B>squashed</B></TT>. To compress a file, use the <TT><B>gzip</B></TT> command. Typing <TT><B>gzip squashed</B></TT> compresses <TT><B>squashed</B></TT> and renames it <TT><B>squashed.gz</B></TT>.</P>

<P>Another type of compressed file you may see ends with the extension .zip. Use <TT><B>unzip</B></TT> to uncompress these files. To create files of this type, use <TT><B>zip</B></TT>.</P>

<P>There&#146;s a couple of other compression systems used by Linux. These provide compressed files ending with .Z or .z (the two are not produced by the same compression tool).</P>

<H3><A NAME="Heading24"></A><FONT COLOR="#000077">Important Directories in the Linux File System</FONT></H3>

<P>Most of the directories that hold Linux system files are &#147;standard.&#148; Other UNIX systems will have identical directories with similar contents. This section summarizes some of the more important directories on your Linux system.

</P>

<H4 ALIGN="LEFT"><A NAME="Heading25"></A><FONT COLOR="#000077">/</FONT></H4>

<P>This is the root directory. It holds the actual Linux program, as well as subdirectories. Do not clutter this directory with your files!

</P>

<H4 ALIGN="LEFT"><A NAME="Heading26"></A><FONT COLOR="#000077">/home</FONT></H4>

<P>This directory holds users&#146; home directories. In other UNIX systems, this can be the <TT><B>/usr</B></TT> or <TT><B>/u</B></TT> directory.</P>

<H4 ALIGN="LEFT"><A NAME="Heading27"></A><FONT COLOR="#000077">/bin</FONT></H4>

<P>This directory holds many of the basic Linux programs. <TT><B>bin</B></TT> stands for <I>binaries</I>, files that are executable and which hold text only computers can understand.</P>

<H4 ALIGN="LEFT"><A NAME="Heading28"></A><FONT COLOR="#000077">/usr</FONT></H4>

<P>This directory holds many other user-oriented directories. Some of the most important are described in the following sections. Other directories found in <TT><B>/usr</B></TT> include</P>

<CENTER>

<TABLE WIDTH="80%"><TR>

<TD WIDTH="20%"><TT><B>docs</B></TT>

<TD WIDTH="90%">Various documents, including useful Linux information

<TR>

<TD><TT><B>man</B></TT>

<TD>The man pages accessed by typing <TT><B>man</B> &lt;<I>command</I>&gt;</TT>

<TR>

<TD><TT><B>games</B></TT>

<TD>The fun stuff!

<TR>

</TABLE>

</CENTER>

<H4 ALIGN="LEFT"><A NAME="Heading29"></A><FONT COLOR="#000077">/usr/bin</FONT></H4>

<P>This directory holds user-oriented Linux programs.

</P>

<H4 ALIGN="LEFT"><A NAME="Heading30"></A><FONT COLOR="#000077">/usr/spool</FONT></H4>

<P>This directory has several subdirectories. <TT><B>mail</B></TT> holds mail files, <TT><B>spool</B></TT> holds files to be printed, and <TT><B>uucp</B></TT> holds files copied between Linux machines.</P>

<H4 ALIGN="LEFT"><A NAME="Heading31"></A><FONT COLOR="#000077">/dev</FONT></H4>

<P>Linux treats <I>everything</I> as a file! The <TT><B>/dev</B></TT> directory holds <I>devices</I>. These are special files that serve as gateways to physical computer components. For instance, if you copy to <TT><B>/dev/fd0</B></TT>, you&#146;re actually sending data to the system&#146;s floppy disk. Your terminal is one of the <TT><B>/dev/tty</B></TT> files. Partitions on the hard drive are of the form <TT><B>/dev/hd0</B></TT>. Even the system&#146;s memory is a device!</P>

<P>A famous device is <TT><B>/dev/null</B></TT>. This is sometimes called the <I>bit bucket</I>. All information sent to <TT><B>/dev/null</B></TT> vanishes&#151;it&#146;s thrown into the trash.</P>

<H4 ALIGN="LEFT"><A NAME="Heading32"></A><FONT COLOR="#000077">/usr/sbin</FONT></H4>

<P>This directory holds system administration files. You must be the <TT><B>root</B></TT> user to run most of these commands.</P>

<H4 ALIGN="LEFT"><A NAME="Heading33"></A><FONT COLOR="#000077">/sbin</FONT></H4>

<P>This directory holds system files that are usually run automatically by the Linux system.

</P><P><BR></P>

<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="164-166.html">Previous</A></TD>

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

<TD><A HREF="170-172.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>





</td>
</tr>
</table>

<!-- begin footer information -->





</body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?