ArticleslgStudy

computer science

Du (Unix)

Du (Unix) is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Du (Unix) rather than just read about it. In short: du is a shell command for reporting the file system storage allocated to files and directory trees. With no command-line arguments, it reports the space allocated to the working directory and to each directory tree that it contains, recursively.

Du (Unix) — main illustration
Du (Unix) — illustration

Key takeaways

  • Du (Unix) belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Du (Unix) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Du (Unix) from memory before moving on to harder problems.

Reference excerpt

du is a shell command for reporting the file system storage allocated to files and directory trees. With no command-line arguments, it reports the space allocated to the working directory and to each directory tree that it contains, recursively. Space allocated to files is reported if files are specified for inclusion. For a symbolic link file, the size of the link file is reported, not what it links to. Although du is short for disk usage, the command is not limited to disk storage. It was developed during the long period of time when disk-based storage was the ubiquitous mass storage technology. du differs from df in that du reports size information of file system items whereas df reports statistics about the storage media as a whole. du can report more detailed information, but can take longer to complete when processing many files. Also, since a storage media may have allocated space that is not associated with an accessible file (i.e. file was deleted but space not freed), df might report more allocated space than du if it were used to calculate the space of all files of a media. Also, the minfree setting that allocates data blocks for the file system and the super user processes creates a discrepancy between total blocks and the sum of used and available blocks. The du command first appeared in version 1 of AT&T UNIX. It is specified by the Single UNIX Specification (SUS). The implementation in GNU coreutils was written by Torbjorn Granlund, David MacKenzie, Paul Eggert, and Jim Meyering. The command is also available for FreeDOS. A similar command is available for Windows in Sysinternals by Mark Russinovich.

Use du accepts any number of parameters that each specify a file by path to specify the starting scope. If none specified, the working directory is used. SUS mandates the following optional options:

-a: In addition to the default output, include information for each non-directory entry -c: Report the grand total of the storage usage for the specified scope -d #: The maximum directory tree depth of the scope. Deeper directories are ignored; for example, 0 sums the starting scope directory only and 1 sums the starting scope directory and its subdirectories -H: Calculate storage usage for link references specified on the command line -k: Show sizes as multiples of 1024 bytes, not 512-byte -L: Calculate storage usage for link references -s: Report only the sum of the usage of the starting scope directory, and not that of subdirectories -x: Only traverse files and directories on which the path argument is specified Some implementations support other options. For example, BSD and GNU support a -h option that selects numbers to be formatted using metric units and notation (e.g. 10 MB) instead of bytes.

Examples Report the storage use for each file and directory tree in kilobytes (-k):

Report the storage use in a more human-readable format (-h:

Report the storage use of all subdirectories and files including hidden files within the working directory sorted by file size:

Report the storage use under in the working directory (-d 1) with a sum total at the end (-c), formatted as human-readable (-h):

For the GNU implementation, --max-depth is used instead of -d. Report the storage use under the root directory (-d 1, trailing /) with a sum total at the end (-c), formatted as human-readable (-h) without traversing into other file systems (-x). Useful when /var, /tmp or other directories are on separate storage from the root directory:

See also Disk Usage Analyzer – Graphical disk usage analyzer for GNOME Filelight – Graphical disk usage analyzer software for KDE List of POSIX commands ncdu – Disk utility program

References

External links

du: estimate file space usage – Shell and Utilities Reference, The Single UNIX Specification, Version 5 from The Open Group du(1) – Linux User Commands Manual

Illustrations

Du (Unix) illustration

Worked examples

Example 1 — a first encounter with Du (Unix)

Start with the simplest possible case. Write down what Du (Unix) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Du (Unix) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Du (Unix) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Du (Unix)

In research
Du (Unix) appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Du (Unix) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Du (Unix) is common in secondary-school and first-year university syllabi. It links to neighbouring topics Disk usage analysis software, Inferno (operating system) commands, Plan 9 commands, so understanding it makes those chapters shorter.
In everyday life
Look for Du (Unix) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Du (Unix)” →

How to study Du (Unix) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Du (Unix) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Du (Unix) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Du (Unix) in simple terms?

du is a shell command for reporting the file system storage allocated to files and directory trees. With no command-line arguments, it reports the space allocated to the working directory and to each directory tree that it contains, recursively.

Why does Du (Unix) matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Du (Unix)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Du (Unix).

Tags

  • Disk usage analysis software
  • Inferno (operating system) commands
  • Plan 9 commands
  • Standard Unix programs
  • Unix SUS2008 utilities
  • Unix file system-related software

Keep exploring