Linux du –max-depth = Mac OS X du -hd1

The du command in macOS, and Unix/Linux systems in general, is used for checking the disk usage of files and directories. The specific command du -hd1 provides a very useful functionality for quickly understanding the space usage in a given directory.


eolsystem ~ % du -hd1
388K ./Music
4.0K ./.vim
0B ./test
22M ./Pictures
eolsystem ~ %

Here's a breakdown of what each part of du -hd1 does:

  1. du: Stands for "disk usage." This command is used to estimate file space usage.
  2. -h: This option stands for "human-readable." When used with du, it formats the output to show sizes in a more comprehensible format using units like K (Kilobytes), M (Megabytes), and G (Gigabytes), instead of showing everything in bytes. This makes it much easier to read and understand the output.
  3. -d1 (or --max-depth=1 in some versions): This limits the depth of directories du reports on. 1 means that du will only report the disk usage of the immediate subdirectories of the current directory (and not their subdirectories). This option helps in summarizing the disk usage of each subdirectory in the current directory without going into more detailed levels.

When you run du -hd1 in a directory on macOS, the command will list the disk usage of all the subdirectories (and files) in the current directory in a human-readable format, such as megabytes and gigabytes, but it won't go deeper into the structure (i.e., it will not show the disk usage of sub-subdirectories). This command is particularly useful for quickly identifying which subdirectories are using the most disk space without getting overwhelmed by too much detail.