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> <<I>directory</I>></TT>.</P>
<P>Before you can remove a directory, it must be empty (the directory can’t hold any files or subdirectories). Otherwise, you see</P>
<!-- CODE SNIP //-->
<PRE>
rmdir: <<I>directory</I>>: 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$ ls
fido/ root/ zippy/
darkstar:/home$ ls zippy
core kazoo stuff
darkstar:/home$ rm zippy/*
darkstar:/home/zippy$ ls zippy
darkstar:/home$ rmdir zippy
rmdir: zippy: Directory not empty
darkstar:~$
</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$ <B>ls -a zippy</B>
./ ../ .bashrc .profile
darkstar:/home$ <B>rm zippy/.*</B>
rm: cannot remove ‘.’ or ‘..’
darkstar:/home$ <B>ls -a zippy</B>
./ ../
darkstar:/home$ <B>rmdir zippy</B>
darkstar:/home$ <B>ls</B>
fido/ root/
darkstar:~$
</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> <<I>directory</I>></TT>. The directory and all its contents are removed.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>Warning: </B><BR>You should use <TT>rm -r</TT> only when you absolutely have to. To paraphrase an old saying, “It’s only a shortcut until you make a mistake.” For example, if you’re logged in as <TT>root</TT>, the following command removes all files from your hard disk, and then it’s “Hello, installation procedure” 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’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—for example, <TT><B>squashed.gz</B></TT>—is a compressed file. To uncompress this particular type of file, type <TT><B>gunzip</B> <<I>file</I>></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’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 “standard.” 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’ 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> <<I>command</I>></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’re actually sending data to the system’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’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—it’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 + -
显示快捷键?