📄 ch24_09.htm
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 24] 24.9 How Much Disk Space? </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly & Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly & Associates, Inc."><METANAME="DC.date"CONTENT="1998-08-04T21:41:36Z"><METANAME="DC.type"CONTENT="Text.Monograph"><METANAME="DC.format"CONTENT="text/html"SCHEME="MIME"><METANAME="DC.source"CONTENT="1-56592-260-3"SCHEME="ISBN"><METANAME="DC.language"CONTENT="en-US"><METANAME="generator"CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"><LINKREV="made"HREF="mailto:online-books@oreilly.com"TITLE="Online Books Comments"><LINKREL="up"HREF="ch24_01.htm"TITLE="24. Other Ways to Get Disk Space"><LINKREL="prev"HREF="ch24_08.htm"TITLE="24.8 Save Space: tar and compress a Directory Tree "><LINKREL="next"HREF="ch24_10.htm"TITLE="24.10 zloop: Run a Command on Compressed Files "></HEAD><BODYBGCOLOR="#FFFFFF"TEXT="#000000"><DIVCLASS="htmlnav"><H1><IMGSRC="gifs/smbanner.gif"ALT="UNIX Power Tools"USEMAP="#srchmap"BORDER="0"></H1><MAPNAME="srchmap"><AREASHAPE="RECT"COORDS="0,0,466,58"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="467,0,514,18"HREF="jobjects/fsearch.htm"ALT="Search this book"></MAP><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch24_08.htm"TITLE="24.8 Save Space: tar and compress a Directory Tree "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 24.8 Save Space: tar and compress a Directory Tree "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 24<BR>Other Ways to Get Disk Space</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch24_10.htm"TITLE="24.10 zloop: Run a Command on Compressed Files "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 24.10 zloop: Run a Command on Compressed Files "BORDER="0"></A></TD></TR></TABLE> <HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-1660">24.9 How Much Disk Space? </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="UPT-ART-1660-IX-DF-COMMAND"></A><ACLASS="indexterm"NAME="UPT-ART-1660-IX-DU-COMMAND"></A><ACLASS="indexterm"NAME="UPT-ART-1660-IX-DISK-SPACE-REPORTS-ON"></A>Two tools, <EMCLASS="emphasis">df</EM> and <EMCLASS="emphasis">du</EM>, report how much disk space isfree and how much is used by any given directory.For each filesystem, <EMCLASS="emphasis">df</EM> tells you thecapacity, how much space is in use, and how much is free.Bydefault, it lists both local and remote (i.e.,<SPANCLASS="link">NFS (<ACLASS="linkend"HREF="ch01_33.htm"TITLE="UNIX Networking and Communications ">1.33</A>)</SPAN>)filesystems.Under BSD UNIX, the output from <EMCLASS="emphasis">df</EM> looks like this:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>df</B></CODE>Filesystem kbytes used avail capacity Mounted on/dev/disk0a 889924 724308 76620 90% //dev/disk3d 505463 376854 78062 83% /benchmarks/dev/disk5e 635287 553121 18637 97% /field/dev/disk2d 505463 444714 10202 98% /research/dev/disk1e 956094 623534 236950 72% /homestoy:/usr 498295 341419 107046 76% /usrtoy:/ 7495 5883 862 87% /root ...</PRE></BLOCKQUOTE></P><PCLASS="para">This report shows information about five local filesystems and tworemote filesystems (from the system <EMCLASS="emphasis">toy</EM>). The <EMCLASS="emphasis">/research</EM> and<EMCLASS="emphasis">/field</EM> filesystems are nearly filled (98 and 97 percent,respectively), while the other filesystems still have a lot of room left.You might want to take some action to free up some storage on these twofilesystems.Note that a BSD filesystemthat is 100 percent full really has 10 percent free space&ndash;but only the<SPANCLASS="link">superuser (<ACLASS="linkend"HREF="ch01_24.htm"TITLE="The Superuser (Root) ">1.24</A>)</SPAN>can use this last 10& percent, and that usually isn't a good idea.</P><PCLASS="para"><EMCLASS="emphasis">df</EM> can be invoked in several other ways:</P><ULCLASS="itemizedlist"><LICLASS="listitem"><PCLASS="para">If you already know that you're interested in a particular filesystem,you can use a command such as <EMCLASS="emphasis">df /homes</EM> or <EMCLASS="emphasis">df& </EM><CODECLASS="literal">.</CODE>(<SPANCLASS="link"><CODECLASS="literal">.</CODE> means "the current directory" (<ACLASS="linkend"HREF="ch01_21.htm"TITLE="Making Pathnames ">1.21</A>)</SPAN>).</P></LI><LICLASS="listitem"><PCLASS="para">If your system uses NFS and you are interested only in localfilesystems, use the command <EMCLASS="emphasis">df -t& 4.2</EM>. You should alwaysuse this command if remote file servers are down. If you have mountedremote disks that are unavailable, <EMCLASS="emphasis">df</EM> will be extremely slow. </P></LI><LICLASS="listitem"><PCLASS="para">If you are interested in<SPANCLASS="link">inode (<ACLASS="linkend"HREF="ch01_22.htm"TITLE="How UNIX Keeps Track of Files: Inodes ">1.22</A>)</SPAN>usage rather than filesystemdata capacity, use the command <EMCLASS="emphasis">df -i</EM>. This produces a similar reportshowing inode statistics.</P></LI></UL><PCLASS="para">If you are using the older System V filesystem, the report from<EMCLASS="emphasis">df</EM> will look different. The information it presents, however, issubstantially the same. Here is a typical report, taken from a XENIXsystem:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>df</B></CODE>/ (/dev/root ): 1758 blocks 3165 i-nodes/u (/dev/u ): 108 blocks 13475 i-nodes/us (/dev/us ): 15694 blocks 8810 i-nodes</PRE></BLOCKQUOTE></P><TABLECLASS="para.programreference"BORDER="1"><TR><THVALIGN="TOP"><ACLASS="programreference"HREF="examples/index.htm"TITLE="df">df</A><BR></TH><TDVALIGN="TOP">There are 1758 physical blocks (always measured as 512-byte blocks,regardless of the filesystem's logical block size) and 3165 inodesavailable on the root filesystem. To find out the filesystem's totalcapacity, use <EMCLASS="emphasis">df -t</EM>. The command <EMCLASS="emphasis">df -l</EM> only reports onyour system's local filesystems, omitting filesystems mounted byNFS or RFS. The <EMCLASS="emphasis">dfspace</EM> command (available onSystems V.3 and V.4) produces a significantly nicer report that'ssimilar to the BSD-style <EMCLASS="emphasis">df</EM>. For each filesystem,<EMCLASS="emphasis">dfspace</EM> shows the amount of free storage both in kilobytes andas a percentage of the filesystem's size.You may also want to try the GNU <EMCLASS="emphasis">df</EM> on the CD-ROM.</TD></TR></TABLE><PCLASS="para">It is often useful to know how much storage a specific directoryrequires. This can help you to determine if any users are occupyingmore than their share of storage. The <EMCLASS="emphasis">du</EM> utility provides sucha report. Here's a simple report from <EMCLASS="emphasis">du</EM>:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>du</B></CODE>107 ./reports888 ./stuff32 ./howard/private33 ./howard/work868 ./howard258 ./project/code769 ./project2634 .</PRE></BLOCKQUOTE></P><PCLASS="para">This command shows that the current directory and allof its subdirectories occupy about 2.5 MB (2634 KB). Thebiggest directories in this group are <EMCLASS="emphasis">stuff</EM> and <EMCLASS="emphasis">howard</EM>, whichhave a total of 888 KB and 868 KB, respectively. The report alsoshows storage occupied by sub-subdirectories (<EMCLASS="emphasis">/howard/work</EM>, etc.).<EMCLASS="emphasis">du</EM>& does not show individual files as separate items, unless youinvoke it with the <EMCLASS="emphasis">-a</EM>& option.Note that System V reports disk usage in 512-byte blocks, not KB.</P><PCLASS="para">The <EMCLASS="emphasis">-s</EM> option tells <EMCLASS="emphasis">du</EM> to report the total amount ofstorage occupied by a directory; it suppresses individual reports forall subdirectories. For example:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>du -s</B></CODE>2634 .</PRE></BLOCKQUOTE></P><PCLASS="para">This is essentially the last line of the previous report.<ACLASS="indexterm"NAME="AUTOID-26648"></A><ACLASS="indexterm"NAME="AUTOID-26649"></A><ACLASS="indexterm"NAME="AUTOID-26650"></A></P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">ML</SPAN> <SPANCLASS="bibliomisc">from O'Reilly & Associates' <CITECLASS="citetitle">System Performance Tuning</CITE>, Chapter 5</SPAN></P></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch24_08.htm"TITLE="24.8 Save Space: tar and compress a Directory Tree "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 24.8 Save Space: tar and compress a Directory Tree "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="book"HREF="index.htm"TITLE="UNIX Power Tools"><IMGSRC="gifs/txthome.gif"SRC="gifs/txthome.gif"ALT="UNIX Power Tools"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch24_10.htm"TITLE="24.10 zloop: Run a Command on Compressed Files "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 24.10 zloop: Run a Command on Compressed Files "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">24.8 Save Space: tar and compress a Directory Tree </TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="index"HREF="index/idx_0.htm"TITLE="Book Index"><IMGSRC="gifs/index.gif"SRC="gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172">24.10 zloop: Run a Command on Compressed Files </TD></TR></TABLE><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><IMGSRC="gifs/smnavbar.gif"SRC="gifs/smnavbar.gif"USEMAP="#map"BORDER="0"ALT="The UNIX CD Bookshelf Navigation"><MAPNAME="map"><AREASHAPE="RECT"COORDS="0,0,73,21"HREF="../index.htm"ALT="The UNIX CD Bookshelf"><AREASHAPE="RECT"COORDS="74,0,163,21"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="164,0,257,21"HREF="../unixnut/index.htm"ALT="UNIX in a Nutshell"><AREASHAPE="RECT"COORDS="258,0,321,21"HREF="../vi/index.htm"ALT="Learning the vi Editor"><AREASHAPE="RECT"COORDS="322,0,378,21"HREF="../sedawk/index.htm"ALT="sed & awk"><AREASHAPE="RECT"COORDS="379,0,438,21"HREF="../ksh/index.htm"ALT="Learning the Korn Shell"><AREASHAPE="RECT"COORDS="439,0,514,21"HREF="../lrnunix/index.htm"ALT="Learning the UNIX Operating System"></MAP></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -