du

du

The du command stands for „disk usage“ and is used to estimate the disk space occupied by files and directories on a Linux system. It’s a versatile tool that can be used by beginners, intermediate users, and even professionals.

What is it used for?

  • Checking file sizes: du displays the total size of each directory or file.
  • File system management: By identifying large files and directories, you can manage your disk space more efficiently.
  • Troubleshooting: It helps in locating issues with disk space consumption.

How to use it?

Basic usage:

bash
du [options] [file/dir]

Common options:

  • -h or --human-readable: Displays sizes in human-readable format (e.g., 1K, 234M).
  • -s or --summarize: Shows the total size for each directory only.
  • -a or --all-files: Includes hidden files and directories.

Examples:

„`bash

Display file sizes in human-readable format

du -h /home/user

Summarize disk usage for all subdirectories of /home

du -sh /home

Show detailed information about a specific directory

du -ah mydirectory
„`

Special hacks?

  • Estimating disk space used by directories: Use du with the -s option to get an overview of each directory’s size.
  • Finding the largest files in a directory tree: Run du with the -a and --max-depth=1 options to see which files take up the most space at the current depth level.

Experience level: This command is suitable for intermediate users who want to gain deeper insights into disk usage. Beginners can start with basic usage, while professionals will find it useful for advanced file system management tasks.

No tags for this post.