What are best practices for using du command?

The du command in Linux is an essential tool for checking directory space usage. Here are some best practices for using the du command effectively:

  • Use -h for Human-Readable Sizes: The -h option makes the output easier to read, displaying sizes in KB, MB, or GB.
  • Summarize Total Size: The -s option provides a summary of the total size of a directory instead of listing each subdirectory.
  • Sort Output: Using the --max-depth=N option limits the output to directories at a specified depth, helping to focus on the most significant areas.
  • Display in Inodes: The -i option shows the number of inodes used, which can be useful for troubleshooting issues related to file systems.
  • Check All Mounted Filesystems: The -a flag will include all files in the output, making it comprehensive.

Example usage of the du command:

du -h -s /path/to/directory

du command Linux disk usage command line tools file system management directory size