Files
oldlinux-files/Ref-docs/POSIX/susv3/utilities/du.html
2024-02-19 00:21:47 -05:00

317 lines
12 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
<title>du</title>
</head>
<body bgcolor="white">
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
</script>
<basefont size="3"> <a name="du"></a> <a name="tag_04_40"></a><!-- du -->
<!--header start-->
<center><font size="2">The Open Group Base Specifications Issue 6<br>
IEEE Std 1003.1-2001<br>
Copyright &copy; 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
<!--header end-->
<hr size="2" noshade>
<h4><a name="tag_04_40_01"></a>NAME</h4>
<blockquote>du - estimate file space usage</blockquote>
<h4><a name="tag_04_40_02"></a>SYNOPSIS</h4>
<blockquote class="synopsis">
<div class="box"><code><tt><sup>[<a href="javascript:open_code('UP')">UP</a>]</sup> <img src="../images/opt-start.gif" alt=
"[Option Start]" border="0"> du</tt> <b>[</b><tt>-a | -s</tt><b>][</b><tt>-kx</tt><b>][</b><tt>-H | -L</tt><b>][</b><i>file</i>
<tt>...</tt><b>]</b><tt><img src="../images/opt-end.gif" alt="[Option End]" border="0"></tt></code></div>
</blockquote>
<h4><a name="tag_04_40_03"></a>DESCRIPTION</h4>
<blockquote>
<p>By default, the <i>du</i> utility shall write to standard output the size of the file space allocated to, and the size of the
file space allocated to each subdirectory of, the file hierarchy rooted in each of the specified files. By default, when a symbolic
link is encountered on the command line or in the file hierarchy, <i>du</i> shall count the size of the symbolic link (rather than
the file referenced by the link), and shall not follow the link to another portion of the file hierarchy. The size of the file
space allocated to a file of type directory shall be defined as the sum total of space allocated to all files in the file hierarchy
rooted in the directory plus the space allocated to the directory itself.</p>
<p>When <i>du</i> cannot <a href="../functions/stat.html"><i>stat</i>()</a> files or <a href=
"../functions/stat.html"><i>stat</i>()</a> or read directories, it shall report an error condition and the final exit status is
affected. Files with multiple links shall be counted and written for only one entry. The directory entry that is selected in the
report is unspecified. By default, file sizes shall be written in 512-byte units, rounded up to the next 512-byte unit.</p>
</blockquote>
<h4><a name="tag_04_40_04"></a>OPTIONS</h4>
<blockquote>
<p>The <i>du</i> utility shall conform to the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href=
"../basedefs/xbd_chap12.html#tag_12_02">Section 12.2, Utility Syntax Guidelines</a>.</p>
<p>The following options shall be supported:</p>
<dl compact>
<dt><b>-a</b></dt>
<dd>In addition to the default output, report the size of each file not of type directory in the file hierarchy rooted in the
specified file. Regardless of the presence of the <b>-a</b> option, non-directories given as <i>file</i> operands shall always be
listed.</dd>
<dt><b>-H</b></dt>
<dd>If a symbolic link is specified on the command line, <i>du</i> shall count the size of the file or file hierarchy referenced by
the link.</dd>
<dt><b>-k</b></dt>
<dd>Write the files sizes in units of 1024 bytes, rather than the default 512-byte units.</dd>
<dt><b>-L</b></dt>
<dd>If a symbolic link is specified on the command line or encountered during the traversal of a file hierarchy, <i>du</i> shall
count the size of the file or file hierarchy referenced by the link.</dd>
<dt><b>-s</b></dt>
<dd>Instead of the default output, report only the total sum for each of the specified files.</dd>
<dt><b>-x</b></dt>
<dd>When evaluating file sizes, evaluate only those files that have the same device as the file specified by the <i>file</i>
operand.</dd>
</dl>
<p>Specifying more than one of the mutually-exclusive options <b>-H</b> and <b>-L</b> shall not be considered an error. The last
option specified shall determine the behavior of the utility.</p>
</blockquote>
<h4><a name="tag_04_40_05"></a>OPERANDS</h4>
<blockquote>
<p>The following operand shall be supported:</p>
<dl compact>
<dt><i>file</i></dt>
<dd>The pathname of a file whose size is to be written. If no <i>file</i> is specified, the current directory shall be used.</dd>
</dl>
</blockquote>
<h4><a name="tag_04_40_06"></a>STDIN</h4>
<blockquote>
<p>Not used.</p>
</blockquote>
<h4><a name="tag_04_40_07"></a>INPUT FILES</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_40_08"></a>ENVIRONMENT VARIABLES</h4>
<blockquote>
<p>The following environment variables shall affect the execution of <i>du</i>:</p>
<dl compact>
<dt><i>LANG</i></dt>
<dd>Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of
IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../basedefs/xbd_chap08.html#tag_08_02">Section 8.2, Internationalization Variables</a> for
the precedence of internationalization variables used to determine the values of locale categories.)</dd>
<dt><i>LC_ALL</i></dt>
<dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd>
<dt><i>LC_CTYPE</i></dt>
<dd>Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as
opposed to multi-byte characters in arguments).</dd>
<dt><i>LC_MESSAGES</i></dt>
<dd>Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard
error.</dd>
<dt><i>NLSPATH</i></dt>
<dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
Determine the location of message catalogs for the processing of <i>LC_MESSAGES .</i> <img src="../images/opt-end.gif" alt=
"[Option End]" border="0"></dd>
</dl>
</blockquote>
<h4><a name="tag_04_40_09"></a>ASYNCHRONOUS EVENTS</h4>
<blockquote>
<p>Default.</p>
</blockquote>
<h4><a name="tag_04_40_10"></a>STDOUT</h4>
<blockquote>
<p>The output from <i>du</i> shall consist of the amount of space allocated to a file and the name of the file, in the following
format:</p>
<pre>
<tt>"%d %s\n", &lt;</tt><i>size</i><tt>&gt;, &lt;</tt><i>pathname</i><tt>&gt;
</tt>
</pre>
</blockquote>
<h4><a name="tag_04_40_11"></a>STDERR</h4>
<blockquote>
<p>The standard error shall be used only for diagnostic messages.</p>
</blockquote>
<h4><a name="tag_04_40_12"></a>OUTPUT FILES</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_40_13"></a>EXTENDED DESCRIPTION</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_40_14"></a>EXIT STATUS</h4>
<blockquote>
<p>The following exit values shall be returned:</p>
<dl compact>
<dt>&nbsp;0</dt>
<dd>Successful completion.</dd>
<dt>&gt;0</dt>
<dd>An error occurred.</dd>
</dl>
</blockquote>
<h4><a name="tag_04_40_15"></a>CONSEQUENCES OF ERRORS</h4>
<blockquote>
<p>Default.</p>
</blockquote>
<hr>
<div class="box"><em>The following sections are informative.</em></div>
<h4><a name="tag_04_40_16"></a>APPLICATION USAGE</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_40_17"></a>EXAMPLES</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_40_18"></a>RATIONALE</h4>
<blockquote>
<p>The use of 512-byte units is historical practice and maintains compatibility with <a href="../utilities/ls.html"><i>ls</i></a>
and other utilities in this volume of IEEE&nbsp;Std&nbsp;1003.1-2001. This does not mandate that the file system itself be based on
512-byte blocks. The <b>-k</b> option was added as a compromise measure. It was agreed by the standard developers that 512 bytes
was the best default unit because of its complete historical consistency on System V (<i>versus</i> the mixed 512/1024-byte usage
on BSD systems), and that a <b>-k</b> option to switch to 1024-byte units was a good compromise. Users who prefer the 1024-byte
quantity can easily alias <i>du</i> to <i>du</i> <b>-k</b> without breaking the many historical scripts relying on the 512-byte
units.</p>
<p>The <b>-b</b> option was added to an early proposal to provide a resolution to the situation where System V and BSD systems give
figures for file sizes in <i>blocks</i>, which is an implementation-defined concept. (In common usage, the block size is 512 bytes
for System V and 1024 bytes for BSD systems.) However, <b>-b</b> was later deleted, since the default was eventually decided as
512-byte units.</p>
<p>Historical file systems provided no way to obtain exact figures for the space allocation given to files. There are two known
areas of inaccuracies in historical file systems: cases of <i>indirect blocks</i> being used by the file system or <i>sparse</i>
files yielding incorrectly high values. An indirect block is space used by the file system in the storage of the file, but that
need not be counted in the space allocated to the file. A <i>sparse</i> file is one in which an <a href=
"../functions/lseek.html"><i>lseek</i>()</a> call has been made to a position beyond the end of the file and data has subsequently
been written at that point. A file system need not allocate all the intervening zero-filled blocks to such a file. It is up to the
implementation to define exactly how accurate its methods are.</p>
<p>The <b>-a</b> and <b>-s</b> options were mutually-exclusive in the original version of <i>du</i>. The POSIX Shell and Utilities
description is implied by the language in the SVID where <b>-s</b> is described as causing &quot;only the grand total&quot; to be reported.
Some systems may produce output for <b>-sa</b>, but a Strictly Conforming POSIX Shell and Utilities Application cannot use that
combination.</p>
<p>The <b>-a</b> and <b>-s</b> options were adopted from the SVID except that the System V behavior of not listing non-directories
explicitly given as operands, unless the <b>-a</b> option is specified, was considered a bug; the BSD-based behavior (report for
all operands) is mandated. The default behavior of <i>du</i> in the SVID with regard to reporting the failure to read files (it
produces no messages) was considered counter-intuitive, and thus it was specified that the POSIX Shell and Utilities default
behavior shall be to produce such messages. These messages can be turned off with shell redirection to achieve the System V
behavior.</p>
<p>The <b>-x</b> option is historical practice on recent BSD systems. It has been adopted by this volume of
IEEE&nbsp;Std&nbsp;1003.1-2001 because there was no other historical method of limiting the <i>du</i> search to a single file
hierarchy. This limitation of the search is necessary to make it possible to obtain file space usage information about a file
system on which other file systems are mounted, without having to resort to a lengthy <a href=
"../utilities/find.html"><i>find</i></a> and <a href="../utilities/awk.html"><i>awk</i></a> script.</p>
</blockquote>
<h4><a name="tag_04_40_19"></a>FUTURE DIRECTIONS</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_40_20"></a>SEE ALSO</h4>
<blockquote>
<p><a href="ls.html"><i>ls</i></a> , the System Interfaces volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href=
"../functions/stat.html"><i>stat</i>()</a></p>
</blockquote>
<h4><a name="tag_04_40_21"></a>CHANGE HISTORY</h4>
<blockquote>
<p>First released in Issue 2.</p>
</blockquote>
<h4><a name="tag_04_40_22"></a>Issue 6</h4>
<blockquote>
<p>This utility is marked as part of the User Portability Utilities option.</p>
<p>The APPLICATION USAGE section is added.</p>
<p>The obsolescent <b>-r</b> option has been removed.</p>
<p>The Open Group Corrigendum U025/3 is applied. The <i>du</i> utility is reinstated, as it had incorrectly been marked LEGACY in
Issue 5.</p>
<p>The <b>-H</b> and <b>-L</b> options for symbolic links are added as described in the IEEE&nbsp;P1003.2b draft standard.</p>
</blockquote>
<div class="box"><em>End of informative text.</em></div>
<hr>
<hr size="2" noshade>
<center><font size="2"><!--footer start-->
UNIX &reg; is a registered Trademark of The Open Group.<br>
POSIX &reg; is a registered Trademark of The IEEE.<br>
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
]</font></center>
<!--footer end-->
<hr size="2" noshade>
</body>
</html>