This du command guide is a follow-up of my previous 90 Linux Commands frequently used by Linux Sysadmins article. Every week, or as time allows, I will publish articles on the ~ 90 commands geared toward Linux sysadmins and Linux power users. Let’s continue this series with the
du (disk usage) command is a standard Unix program used to estimate file space used under a particular directory or files on a file system.
du takes a single argument, specifying a pathname for du to work. If the path is not given, the working directory is used. On Linux, some of the available
du options are:
--all– write counts for all files, not just directories.
--apparent-size– print apparent sizes, rather than disk usage. (Although the apparent size is usually smaller, it may be larger due to internal fragmentation, indirect blocks, etc.
--block-size=SIZE– scale sizes by SIZE before printing them. (e.g., ‘-BM’ prints sizes in units of 1,048,576 bytes.)
--bytes– equivalent to ‘
--total– produce a grand-total.
--dereference-args– dereference only symlinks that are listed on the command line.
--max-depth=N– print the total for a directory (or file, with –all) only if it is N or fewer levels below the command line argument;
--max-depth=0is the same as –summarize.
--files0-from=F– summarize disk usage of the NUL-terminated file names specified in file F; if F is -, then read names from standard input.
--human-readable– print sizes in human-readable format (e.g., 1K 234M 2G).
--inodes– list inode usage information instead of block usage.
--dereference– dereference all symbolic links.
--count-links– count sizes many times if hard-linked.
-m like --block-size=1M
--no-dereference– don’t follow any symbolic links (this is the default).
--separate-dirs– for directories, do not include the size of subdirectories.
du disk usage command examples
To list the sizes of a directory and any subdirectories in the given unit (B/KB/MB), use:
du -b|k|m path/to/directory
To list the sizes of a directory and any subdirectories in human-readable form (i.e., auto-selecting the appropriate unit 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 of all the 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 subdirectories of the current directory and show a cumulative total at the end, use:
du -ch */*.jpg
du command useful reading:
du alternatives and related commands: