1DU(1P) POSIX Programmer's Manual DU(1P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 du — estimate file space usage
13
15 du [-a|-s] [-kx] [-H|-L] [file...]
16
18 By default, the du utility shall write to standard output the size of
19 the file space allocated to, and the size of the file space allocated
20 to each subdirectory of, the file hierarchy rooted in each of the spec‐
21 ified files. By default, when a symbolic link is encountered on the
22 command line or in the file hierarchy, du shall count the size of the
23 symbolic link (rather than the file referenced by the link), and shall
24 not follow the link to another portion of the file hierarchy. The size
25 of the file space allocated to a file of type directory shall be
26 defined as the sum total of space allocated to all files in the file
27 hierarchy rooted in the directory plus the space allocated to the
28 directory itself.
29
30 When du cannot stat() files or stat() or read directories, it shall
31 report an error condition and the final exit status is affected. A file
32 that occurs multiple times under one file operand and that has a link
33 count greater than 1 shall be counted and written for only one entry.
34 It is implementation-defined whether a file that has a link count no
35 greater than 1 is counted and written just once, or is counted and
36 written for each occurrence. It is implementation-defined whether a
37 file that occurs under one file operand is counted for other file oper‐
38 ands. The directory entry that is selected in the report is unspeci‐
39 fied. By default, file sizes shall be written in 512-byte units,
40 rounded up to the next 512-byte unit.
41
43 The du utility shall conform to the Base Definitions volume of
44 POSIX.1‐2017, Section 12.2, Utility Syntax Guidelines.
45
46 The following options shall be supported:
47
48 -a In addition to the default output, report the size of each
49 file not of type directory in the file hierarchy rooted in
50 the specified file. The -a option shall not affect whether
51 non-directories given as file operands are listed.
52
53 -H If a symbolic link is specified on the command line, du shall
54 count the size of the file or file hierarchy referenced by
55 the link.
56
57 -k Write the files sizes in units of 1024 bytes, rather than the
58 default 512-byte units.
59
60 -L If a symbolic link is specified on the command line or
61 encountered during the traversal of a file hierarchy, du
62 shall count the size of the file or file hierarchy referenced
63 by the link.
64
65 -s Instead of the default output, report only the total sum for
66 each of the specified files.
67
68 -x When evaluating file sizes, evaluate only those files that
69 have the same device as the file specified by the file oper‐
70 and.
71
72 Specifying more than one of the mutually-exclusive options -H and -L
73 shall not be considered an error. The last option specified shall
74 determine the behavior of the utility.
75
77 The following operand shall be supported:
78
79 file The pathname of a file whose size is to be written. If no
80 file is specified, the current directory shall be used.
81
83 Not used.
84
86 None.
87
89 The following environment variables shall affect the execution of du:
90
91 LANG Provide a default value for the internationalization vari‐
92 ables that are unset or null. (See the Base Definitions vol‐
93 ume of POSIX.1‐2017, Section 8.2, Internationalization Vari‐
94 ables for the precedence of internationalization variables
95 used to determine the values of locale categories.)
96
97 LC_ALL If set to a non-empty string value, override the values of
98 all the other internationalization variables.
99
100 LC_CTYPE Determine the locale for the interpretation of sequences of
101 bytes of text data as characters (for example, single-byte as
102 opposed to multi-byte characters in arguments).
103
104 LC_MESSAGES
105 Determine the locale that should be used to affect the format
106 and contents of diagnostic messages written to standard
107 error.
108
109 NLSPATH Determine the location of message catalogs for the processing
110 of LC_MESSAGES.
111
113 Default.
114
116 The output from du shall consist of the amount of space allocated to a
117 file and the name of the file, in the following format:
118
119
120 "%d %s\n", <size>, <pathname>
121
123 The standard error shall be used only for diagnostic messages.
124
126 None.
127
129 None.
130
132 The following exit values shall be returned:
133
134 0 Successful completion.
135
136 >0 An error occurred.
137
139 Default.
140
141 The following sections are informative.
142
144 None.
145
147 None.
148
150 The use of 512-byte units is historical practice and maintains compati‐
151 bility with ls and other utilities in this volume of POSIX.1‐2017. This
152 does not mandate that the file system itself be based on 512-byte
153 blocks. The -k option was added as a compromise measure. It was agreed
154 by the standard developers that 512 bytes was the best default unit
155 because of its complete historical consistency on System V (versus the
156 mixed 512/1024-byte usage on BSD systems), and that a -k option to
157 switch to 1024-byte units was a good compromise. Users who prefer the
158 1024-byte quantity can easily alias du to du -k without breaking the
159 many historical scripts relying on the 512-byte units.
160
161 The -b option was added to an early proposal to provide a resolution to
162 the situation where System V and BSD systems give figures for file
163 sizes in blocks, which is an implementation-defined concept. (In common
164 usage, the block size is 512 bytes for System V and 1024 bytes for BSD
165 systems.) However, -b was later deleted, since the default was eventu‐
166 ally decided as 512-byte units.
167
168 Historical file systems provided no way to obtain exact figures for the
169 space allocation given to files. There are two known areas of inaccura‐
170 cies in historical file systems: cases of indirect blocks being used by
171 the file system or sparse files yielding incorrectly high values. An
172 indirect block is space used by the file system in the storage of the
173 file, but that need not be counted in the space allocated to the file.
174 A sparse file is one in which an lseek() call has been made to a posi‐
175 tion beyond the end of the file and data has subsequently been written
176 at that point. A file system need not allocate all the intervening
177 zero-filled blocks to such a file. It is up to the implementation to
178 define exactly how accurate its methods are.
179
180 The -a and -s options were mutually-exclusive in the original version
181 of du. The POSIX Shell and Utilities description is implied by the
182 language in the SVID where -s is described as causing ``only the grand
183 total'' to be reported. Some systems may produce output for -sa, but a
184 Strictly Conforming POSIX Shell and Utilities Application cannot use
185 that combination.
186
187 The -a and -s options were adopted from the SVID except that the System
188 V behavior of not listing non-directories explicitly given as operands,
189 unless the -a option is specified, was considered a bug; the BSD-based
190 behavior (report for all operands) is mandated. The default behavior of
191 du in the SVID with regard to reporting the failure to read files (it
192 produces no messages) was considered counter-intuitive, and thus it was
193 specified that the POSIX Shell and Utilities default behavior shall be
194 to produce such messages. These messages can be turned off with shell
195 redirection to achieve the System V behavior.
196
197 The -x option is historical practice on recent BSD systems. It has been
198 adopted by this volume of POSIX.1‐2017 because there was no other his‐
199 torical method of limiting the du search to a single file hierarchy.
200 This limitation of the search is necessary to make it possible to
201 obtain file space usage information about a file system on which other
202 file systems are mounted, without having to resort to a lengthy find
203 and awk script.
204
206 A future version of this standard may require that a file that occurs
207 multiple times shall be counted and written for only one entry, even if
208 the occurrences are under different file operands.
209
211 ls
212
213 The Base Definitions volume of POSIX.1‐2017, Chapter 8, Environment
214 Variables, Section 12.2, Utility Syntax Guidelines
215
216 The System Interfaces volume of POSIX.1‐2017, fstatat()
217
219 Portions of this text are reprinted and reproduced in electronic form
220 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
221 table Operating System Interface (POSIX), The Open Group Base Specifi‐
222 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
223 Electrical and Electronics Engineers, Inc and The Open Group. In the
224 event of any discrepancy between this version and the original IEEE and
225 The Open Group Standard, the original IEEE and The Open Group Standard
226 is the referee document. The original Standard can be obtained online
227 at http://www.opengroup.org/unix/online.html .
228
229 Any typographical or formatting errors that appear in this page are
230 most likely to have been introduced during the conversion of the source
231 files to man page format. To report such errors, see https://www.ker‐
232 nel.org/doc/man-pages/reporting_bugs.html .
233
234
235
236IEEE/The Open Group 2017 DU(1P)