du – Estimate and summarize file and directory space usage on Linux

it of the order The guide is a follow-up to my previous 90 Linux Commands Often Used by Linux Sysadmins article. Every week, or as time permits, I will publish articles on ~90 commands geared to Linux sysadmins and Linux power users. let’s continue this series du Permission.

du The (disk usage) command is a standard Unix program used to estimate the file space used under files on a particular directory or file system. du Takes a single argument, specifying a pathname for du to work. If path is not given, the working directory is used. On Linux, some available du The options are:

  • -a, --all –counts for all files, not just directories.
  • --apparent-size – Print clear size instead of disk usage. (Although the apparent size is usually small, it may be larger due to internal fragmentation, indirect blocks, etc.
  • -B, --block-size=SIZE – Scale the size by SIZE before printing. (For example, -bm prints the size in units of 1,048,576 bytes.)
  • -b, --bytes – Equal to ‘--apparent-size --block-size=1,
  • -c, --total – Produce a grand total.
  • -D, --dereference-args –dereferences only symlinks that are listed on the command line.
  • -d, --max-depth=N –print the total for a directory (or file, with -all ) only if it is N or less than a level below the command line argument; --max-depth=0 Same – in short.
  • --files0-from=F – Summarize the disk usage of the NUL-terminated filenames specified in file f; If F – , read the name from standard input.
  • -h, --human-readable – Print size in a human-readable format (eg, 1K 234M 2G).
  • --inodes – List inode usage information instead of block usage.
  • -k to like --block-size=1K
  • -L, --dereference – Removal of all symbolic links.
  • -l, --count-links – Count size multiple times when hard-linked.
  • -m like --block-size=1M
  • -P, --no-dereference – Do not follow any symbolic links (this is the default).
  • -S, --separate-dirs –For directories, do not include the size of the subdirectories.

du disk usage command example

To list the size of a directory and any subdirectories in a given unit (b/kb/mb), use:

du -b|k|m path/to/directory

To list the size of a directory and any subdirectories in human-readable form (ie, automatic selection of the appropriate entity for each size), use:

du -h path/to/directory

To show the size of a single directory in human-readable units, use:

du -sh path/to/directory

To list the human-readable sizes of a directory and all files and directories within it, use:

du -ah path/to/directory

To list the human-readable sizes of a directory and any subdirectories, up to N levels deep, use:

du -h --max-depth=N path/to/directory

To list the human-readable size of all .jpg files in the current directory’s subdirectories and show a cumulative total at the end, use:

du -ch */*.jpg

du command useful read:

du option and related commands:

  • ncdu – A disk utility for Unix systems.
  • df – Report disk usage by filesystem.

Leave a Comment