Clear, practical technology insights BSOD Code Lookup · Windows Error Code Lookup · Wi-Fi Troubleshooting · PC Troubleshooting Checklist

The Du (Disk Usage) Commands Are Most Handy in Linux

Learn the key facts about The Du (Disk Usage) Commands Are Most Handy in Linux, with clear context, practical guidance, and useful takeaways.

Table of Contents

This updated guide examines The Du (Disk Usage) Commands Are Most Handy in Linux and organizes the essential facts, background, and practical takeaways in clear American English.

Basic usage

du /path/to/directory

Runduwith a directory to see the full analysis of the disk space that each folder holds. Each directory will be listed in turn in the standard output, so large directories or full system scans can generate tens of thousands of result streams and take a considerable amount of time. As a result, basicducommands are often added with flags (which will be shown below). Any of these flags can be combined with another flag, although some combinations are mutually exclusive because they are contradictory.

Control output

The Du (Disk Usage) Commands Are Most Handy in Linux — contextual image 1

du -c

Display a line at the bottom of the output to indicate the total amount of disk space used by the scanned folders.

du -s

Show only a summary of the total amount of disk space used by the specified directory. No output is displayed until the calculation process is complete.

du > du-report.txt

People who use the command line will recognize this command, but not everyone. This command outputs the result of the command to a text file in the current directory, named 'du-report.txt'.

du | less

This command produces cleaner and more readable results. You can browse content with fewer navigation shortcuts.

Change the capacity display

The Du (Disk Usage) Commands Are Most Handy in Linux — contextual image 2

Note that the file size will usually be rounded when specific units are specified. For example, the 4KB file will be displayed as 0MB if the -m flag is called, while the 750KB file will be displayed as 1MB.

du -h

Displayed in a readable format with the appropriate volumes listed, such as kilobytes, megabytes and gigabytes, instead of the standard block (block) size.

du -k

Displays the number of blocks in 1024-byte blocks (1 kilobyte).

du -m

Displays the number of blocks in blocks of 1,048,576 bytes (1 megabyte).

du -g

Displays the number of blocks in blocks 1,073,741,824 bytes (1 gigabyte).

The Du (Disk Usage) Commands Are Most Handy in Linux — contextual image 3

du -L

Follow the symbolic links in the command line and file hierarchy. On the other hand, the space occupied by the symbolic link itself will be reported (usually the minimum in the file system) rather than the directory tree that the symbolic link points to.

du -a

Displays the disk usage of all files, not just folders.

du /path/to/file.txt

Displays the disk usage of a specific file, as named in the command.

The Du (Disk Usage) Commands Are Most Handy in Linux — contextual image 4

du -X FILE

Exclude files that match any pattern in the specified string.

du --exclude="*.o"

Exclude files and subdirectories according to the pattern. In this example, all folders including the '*.o' string will be ignored. Note that these are pattern shells, not regular expressions. Thus, the control characters are limited to * , matching any string with 0 or more characters and?, matches any one character. The above command will exclude these files from the directory capacity calculation process. If flag -a is used, the excluded file will be ignored in the output.

du --threshold=SIZE

Exclude items that are less than SIZE if it is a positive value or items greater than SIZE if it is a negative value. SIZE is an integer and has one unit (optional). For example, the--threshold=1MBcommand will ignore all files smaller than 1 megabyte (1000 ^ 2 bytes). Units including K, M, G, T, P, E, Z, Y represent kibibyte, mebibyte, gibibyte, etc.. or KB, MB, GB, TB, represent kilobytes, megabytes, gigabytes, etc. This can be a useful tool to find the largest files on the system with a command likedu --threshold=1GB.

du -d N

Set the maximum depth for N folders. This flag can take any positive integer. With this setting,duwill scan as many as 2 subdirectories in the specified directory. If other subdirectories exist, they will not be scanned individually. Instead, their value will be included in the reported directories. Note that -d 0 will report the same result as the -s flag .

For example, consider the directory path 'dir1 / dir2 / dir3 / dir4', containing 1 parent directory and 3 subdirectories. The commanddu -d 2 dir1will scan to dir3.Dir3 will include files in dir4, although dir4 is not listed separately.

Theducommand isduuseful when paired with other utilities, such as thedu -a / | sort -n -r | head -n 10commanddu -a / | sort -n -r | head -n 10du -a / | sort -n -r | head -n 10. This command will search your entire file system ( du -a / ), sort results by size ( sort -n -r ), and then display only the top 10 results ( head -n 10 ). Basically, this is a shortcut to the 10 largest files on your computer. Combineduwith other commands via pipes to produce even more useful results.

Hope you are succesful.

FAQ

What is The Du (Disk Usage) Commands Are Most Handy in Linux about?

It provides a structured overview of linux, explains the main context, and highlights practical takeaways for readers.

Why does this topic matter?

Understanding the main concepts helps readers evaluate the issue, avoid common mistakes, and make better-informed decisions.

How should readers use this information?

Use the guidance as a practical starting point, confirm details that may have changed, and follow current product, safety, or security recommendations.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.