Cheatsheets
HomeWriteupsResourcesCheatsheets
Linux
Linux
  • Know Yourself and Your System
    • id
    • logname
    • uname
    • w
    • who
    • whoami
  • Surfing / Knowing Your File System
    • cd
    • df
    • du
    • ls
    • pwd
    • stat
    • tree
  • Knowing About Files / Commands
    • alias
    • file
    • info
    • whatis
    • apropos
    • man
    • help
    • history
    • script
  • Manipulating Files / Directories
    • touch
    • mkdir
    • rm
    • rmdir
    • cp
    • mv
    • ln
  • Interacting with Files
    • cat
    • head
    • less
    • middle
    • more
    • tail
  • STROPS / Text Manipulation
    • awk
    • cut
    • grep
    • jq
    • join
    • paste
    • sed
    • sort
    • tr
    • uniq
    • xargs
    • xclip
    • wc
    • tee
    • echo
    • comm
    • diff
    • patch
    • aspell
    • Combos
  • Formatting the Output
    • nl
    • fold
    • fmt
    • pr
    • printf
  • Searching / Finding
    • find
    • locate
    • which
    • whereis
    • type
  • Web Interaction
    • curl
    • wget
  • xxd
  • References
Powered by GitBook
On this page
  • Introduction
  • Syntax
  • Important Flags
  • Examples

Was this helpful?

  1. Surfing / Knowing Your File System

du

du linux command cheatsheet by Thamizhiniyan C S

Introduction

du is a command in linux (short for disk usage) which helps you identify what files/directories are consuming how much space.


Syntax

du [OPTION]... [FILE]...

du [OPTION]... --files0-from=F


Important Flags

Flag
Description

-0, --null

End each output line with NULL

-a or --all

Displays disk usage information for all files and directories, including hidden ones.

--apparent-size

Print apparent sizes, rather than disk usage

-B, --block-size=SIZE

Scale sizes to SIZE before printing on console

-c or --total

Shows the total disk usage in addition to individual usage for directories and files.

-d, --max-depth=N

Print total for directory only if it is N or fewer levels below command line argument

-h or --human-readable

Displays sizes in human-readable format, using units such as KB, MB, GB, etc. This option makes it easier to interpret the disk usage information.

-S, -separate-dirs

For directories, don’t include size of subdirectories

-s or --summarize

Provides a summary of the disk usage for the specified directory or file, without displaying individual usage details for subdirectories.

--time

Show time of last modification of any file or directory

--exclude

Excludes specific directories or files from disk usage calculation based on patterns or names.


Examples

Command
Description

To display the disk usage information for all files and directories, including hidden ones in the home directory.

You can print sizes in human-readable format (e.g., 1K 234M 2G), using the `-h` option.

Combine `-a` and `-h` flags together to check all files and folder sizes.

Use -c option to print total size

To print sizes to particular level, use -d option with level no.

Now try with level 2, you will get some extra directories

Get summary of file system using -s option

Print apparent sizes, rather than disk usage; although the apparent size is usually smaller, it may be larger due to holes in (‘sparse’) files, internal fragmentation, indirect blocks, and the like.

Get the timestamp of last modified using --time option

Check the timestamp of the last modification of files and directories to 1 level.

To find the largest directories, you can use the du command with the --max-depth option.

The du command supports the -h option to display sizes in a human-readable format (e.g., KB, MB, GB).

You can combine the find command with du to identify large files.

To exclude specific directories, use the --exclude option with the du command.

PreviousdfNextls

Last updated 11 months ago

Was this helpful?

du -a /home
du -h /home
du -a -h /home
du -c -h /home
du -d 1 /home
du -d 2 /home
du -s /home
du -sh --apparent-size /home
du --time -h /home
du --time -d 1 /home/
du --max-depth=1 /path
du -h /path
find /path -type f -exec du -h {} + | sort -rh | head -n 10
du -h --exclude=/path/to/exclude /path