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

📄 564-567.html

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

<HEAD>

<TITLE>Using Linux:System Maintenance</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=0789716232//-->

<!--TITLE=Using Linux//-->

<!--AUTHOR=William Ball//-->

<!--PUBLISHER=Macmillan Computer Publishing//-->

<!--IMPRINT=Que//-->

<!--CHAPTER=31//-->

<!--PAGES=564-567//-->

<!--UNASSIGNED1//-->

<!--UNASSIGNED2//-->



<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="561-564.html">Previous</A></TD>

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

<TD><A HREF="567-568.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>

<P><BR></P>

<H3><A NAME="Heading12"></A><FONT COLOR="#000077">Maximizing Disk Space</FONT></H3>

<P>Generally, it&#146;s best not to allow free space on your hard drive to fall below 25&#150;30 percent of your hard drive&#146;s total capacity. The following sections examine ways to keep an eye on disk space, and (more importantly) ways to reclaim parts of a shrinking hard disk pie.

</P>

<H4 ALIGN="LEFT"><A NAME="Heading13"></A><FONT COLOR="#000077">Performing System Cleanups</FONT></H4>

<P>While the kernel and other Linux processes run, they generate a number of &#147;housekeeping&#148; files. Often, Linux automatically disposes of these files but sometimes you must take matters into your own hands. For instance, if you are creating your own logs, use a redirect command like <TT>&gt;&gt;</TT> (append); the files used by that redirect will continue to grow until removed.</P>

<P>Linux provides two commands to check on disk usage, <TT>df</TT> and <TT>du,</TT> described in the following two command examples:</P>

<!-- CODE SNIP //-->

<PRE>

#df

Filesystem        1024-blocks  Used Available Capacity

 Mounted on

/dev/hda5             128790   61203    60936     50%   /

/dev/hda7             257598  172332    71962     71%

  /usr

/dev/fd0                1423     471      952     33%

/mnt/floppy

</PRE>

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

<P><TT>df</TT> (disk free space) reports on the total number of blocks used and free on all mounted partitions. It&#146;s good for getting an overall snapshot of the space available on the entire system. Its compatriot, <TT>du</TT>, allows you to examine individual files and directories for space usage, a little like <TT>ls</TT> with the <TT>-l</TT> option:</P>

<!-- CODE SNIP //-->

<PRE>

#du

15        ./taper_info

1        ./docs/f2

2        ./docs/x

2853    .

</PRE>

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

<P>You can use these commands in shell scripts to automate monitoring of system space usage.

</P>

<P>You can also use the <TT>find</TT> command with the size (<TT>-s</TT>) option to  generate lists of large files that bear examining:</P>

<!-- CODE SNIP //-->

<PRE>

#find -s &#43;1000k -print &gt; /home/me/filemaint/bigfilelist

</PRE>

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

<P>This command prints a list of files larger than 1 MB (1,000 KB) in the designated log file. You can also run this command using the <TT>crontab</TT> feature to receive email listing those files:</P>

<!-- CODE SNIP //-->

<PRE>

* 8 * * Mon find -s &#43;1000k -print

</PRE>

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

<P>This command checks for large files every Monday at 8:00 a.m. (a good way to enjoy light entertainment on Monday mornings is to see some of the gargantuan files created over the last week).

</P>

<P>Aside from looking for files created by users, there are several places that you can check for files that need to be cleaned up. The best place to start is in the <TT>/etc/syslog.conf</TT> file. This file maintains a listing of all of the logs used by the <TT>syslogd</TT> daemon, a &#147;system logger&#148; started when you boot Linux:</P>

<!-- CODE //-->

<PRE>

#cat /etc/syslog.conf

# Log all kernel messages to the console.

# Logging much else clutters up the screen.

kern.*

/dev/console

# Log anything (except mail) of level info or higher.

# Don&#146;t log private authentication messages!

*.info;mail.none;authpriv.none                       /var/log/

messages

# The authpriv file has restricted access.

authpriv.*

/var/log/secure

# Log all the mail messages in one place.

mail.*

/var/log/maillog

# Everybody gets emergency messages, plus log them on another # machine.

*.emerg                                             *

# Save mail and news errors of level err and higher in a

# special file.

uucp,news.crit

/var/log/spooler

</PRE>

<!-- END CODE //-->

<P>In this file, the lines starting with <TT>#</TT> signs are comments; the other lines instruct the <TT>syslog</TT> daemon how to handle log messages. The Linux system logs a variety of messages to help with everything from lost mail to system crashes. Almost every message contains a time, machine name, and the name of the program that generated it. The <TT>syslog</TT> daemon also categorizes messages by order of importance, ranging from simple system debugging and info messages to high-priority critical and emergency (<TT>emerg</TT>) messages.</P>

<P>In addition to being routed by severity, messages are earmarked based on the facility (<TT>cron</TT>, <TT>mail</TT>, and so on) associated with them. So, as you can see above, mail log messages are handled differently than kernel (<TT>kern</TT>) messages. Some of these logs can be good places to look if you&#146;re having problems with a particular feature of Linux (like mail).</P>

<P>You can see how, if the system were left up for some time with no other housecleaning done, some of the files might get large. Almost all of these <TT>syslogd</TT> logs are stored in <TT>/var/log</TT>, so this is a good place to check for files experiencing runaway growth:</P>

<!-- CODE SNIP //-->

<PRE>

#find /var/log -s &#43;250k -print

</PRE>

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

<P>It&#146;s also worth becoming a little familiar with the Linux File System Standard to help identify other likely places to clean (the Red Hat documentation contains a description of how Red Hat&#146;s filesystem structure conforms to the Linux File System Standard). Two candidates are the <TT>tmp</TT> directories: <TT>/tmp</TT> and <TT>/var/tmp</TT>. These directories are used as &#147;dumping grounds&#148; by various applications and utilities, and if the system isn&#146;t rebooted periodically, they too can become larger than you&#146;d like:</P>

<!-- CODE SNIP //-->

<PRE>

#ls /var/tmp

taper00291oaa

taper00291paa

taper00420caa

taper00420daa

taper01047caa

taper01047daa

</PRE>

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

<P>The <TT>/var/tmp</TT> file contains a set of <TT>taper</TT>-related files. If you&#146;re not sure whether <TT>taper</TT> still needs these (it probably doesn&#146;t), move them to another directory and run a <TT>taper</TT> backup and/or restore. Assuming <TT>taper</TT> runs satisfactorily, it should be safe to remove these files.</P>

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>SEE ALSO</B>

<DL>

<DD><B>&#149;</B>&nbsp;&nbsp;For more information about the <TT>find</TT> command, see page 548.

<DD><B>&#149;</B>&nbsp;&nbsp;For more information about the <TT>crontab</TT> utility, see page 435.

<DD><B>&#149;</B>&nbsp;&nbsp;For more information about Linux kernel management, see page 569.

<DD><B>&#149;</B>&nbsp;&nbsp;For more information about using the Linux <TT>mail</TT> utility, see page 179.

<DD><B>&#149;</B>&nbsp;&nbsp;For information about Linux system daemons, see page 467.

</DL>

<HR></FONT>

</BLOCKQUOTE>

<P><BR></P>

<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="561-564.html">Previous</A></TD>

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

<TD><A HREF="567-568.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 + -