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

📄 ch24_18.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 24] 24.18 Huge Files Might Not Take a Lot of Disk Space </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly &amp; Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly &amp; Associates, Inc."><METANAME="DC.date"CONTENT="1998-08-04T21:41:48Z"><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_17.htm"TITLE="24.17 Disk Quotas "><LINKREL="next"HREF="part04.htm"TITLE="IV. Looking Inside 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_17.htm"TITLE="24.17 Disk Quotas "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 24.17 Disk Quotas "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="PART"HREF="part04.htm"TITLE="IV. Looking Inside Files "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: IV. Looking Inside Files "BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-0392">24.18 Huge Files Might Not Take a Lot of Disk Space </A></H2><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-27058"></A><ACLASS="indexterm"NAME="AUTOID-27060"></A><ACLASS="indexterm"NAME="AUTOID-27063"></A>If you're doing filesystem cleanup, you use <EMCLASS="emphasis">ls -l</EM>, and see afile with ten million bytes...&quot;Yipes!&quot; you say, &quot;That must be eating a lot of disk space!&quot;But if you remove the file,<SPANCLASS="link"><EMCLASS="emphasis">df</EM> (<ACLASS="linkend"HREF="ch24_09.htm"TITLE="How Much Disk Space? ">24.9</A>)</SPAN>shows almost no difference in disk space.Why?</P><PCLASS="para">It could be a <EMCLASS="emphasis">sparse file</EM>,a file with a lot more NUL characters in it than anythingelse (that's a general definition, but it's basically correct).The command<SPANCLASS="link"><EMCLASS="emphasis">ls -ls</EM> (<ACLASS="linkend"HREF="ch17_14.htm"TITLE="Searching for Files by Size ">17.14</A>)</SPAN>will show you sparse files; the disk usage in the first column will berelatively much smaller than the character count:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>ls -ls</B></CODE>total 128  64 -rw-r--r--  1 jerry     8413616 Nov  9 16:49 core  64 -rw-r--r--  1 jerry       64251 Nov  7 18:22 dns.tar</PRE></BLOCKQUOTE></P><PCLASS="para">Programs that use <EMCLASS="emphasis">dbm</EM> (<EMCLASS="emphasis">d</EM>ata<EMCLASS="emphasis">b</EM>ase <EMCLASS="emphasis">m</EM>anagement subroutines) often createsparse files because <EMCLASS="emphasis">dbm</EM> usesfile location as part of its hashing and tries to spread out entriesin the database file so there is lots of blank space between them.</P><PCLASS="para">ManyUNIX filesystems (although not all&nbsp;- the Andrew File System, for example doesnot) support the ability to greatly reduce theamount of space taken up by a file that is mostly NULs by not reallystoring the file blocks that are filled with NULs.Instead, the OS keeps track of how many blocks of NULs there arebetween each block that has something other than NULs in it, andfeeds NULs to anybody who tries to read the file, even thoughthey're not really being read off a disk.</P><PCLASS="para">You can create a sparse file in C by using <EMCLASS="emphasis">fopen</EM>(3) to open a file and<EMCLASS="emphasis">fseek</EM>(3) to move the file pointer farpast the end of the file without writing anything.The file up to where you <EMCLASS="emphasis">fseek</EM> will contain NULs, and the kernel(probably)won't save all of those NULs to disk.</P><PCLASS="para">By the way, sparse files can be a problem to copy.The kernel isn't smart enough to figure out you're feeding it a sparsefile if you actually feed it the NULs. Therefore, standard file copyingprogramslike <EMCLASS="emphasis">cp</EM> that just read the file in and write it out in a differentlocation lose, because they end up creating a file that really doestake up as much as space physically as there are NULs in the abstractfile object.Then your disk space might really be in trouble.[Some operating systems have a <EMCLASS="emphasis">cp -z</EM> option to solve this problem. <EMCLASS="emphasis">-TC</EM>&nbsp;]</P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">JIK</SPAN>, <SPANCLASS="authorinitials">JP</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_17.htm"TITLE="24.17 Disk Quotas "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 24.17 Disk Quotas "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="PART"HREF="part04.htm"TITLE="IV. Looking Inside Files "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: IV. Looking Inside Files "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">24.17 Disk Quotas </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">IV. Looking Inside 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 &amp; 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 + -