linux – df and du

Linux command to check disk space:

To check the diskspace in linux, we have primarily two commands:

  • df
  • du

they multiple switches and variations to get the desired output:

df command:

The df reports file system usage. For example:

$ df
Filesystem 1K-blocks Used      Available Use% Mounted on
/dev/sda4  40074084  7372872   2194212   68%  /
none       1542384   7768      1541516   2%   /mnt
none       1549012   8852      1538764   2%   /dev/shm
/dev/sda2  5039616   3776924   1024792   79%  /home
/dev/sda3  329715196 165519248 13195948  91%  /media/Data

df command – Shows the amount of disk space used and available on Linux file systems.

Syntax: df

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

Options

-a–allinclude all files.
-B–block-size=SIZEScale sizes by SIZE before printing them. E.g., ‘-BM‘ prints sizes in units of 1,048,576 bytes. See “SIZE Format” below for more information.
–totalDisplay a grand total.
-h–human-readablePrint sizes in human readable format (e.g., 1K 234M 2G).
-H–siSame as -h, but use powers of 1000 instead of 1024.
-i–inodesList inode information instead of block usage.
-kLike –block-size=1K.
-l–localLimit listing to local file systems.
–no-syncDo not invoke a sync before getting usage info, which is the default setting.
-P–portabilityUse the POSIX output format.
–syncInvoke a sync before getting usage info.
-t–type=TYPELimit listing to file systems of type TYPE.
-T–print-typePrint file system type.
-x–exclude-type=TYPELimit listing to file systems not of type TYPE.
-vIgnored; included for compatibility reasons.
–helpDisplay a help message and exit.
–versionOutput version information and exit.

SIZE Format

Display values are in units of the first available SIZE from –block-size, and the DF_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environment variables. Otherwise, units default to 1024 bytes (or 512 if POSIXLY_CORRECT is set).

SIZE is an integer and optional unit (example: 10M is 10*1024*1024). Units are K, M, G, T, P, E, Z, Y (powers of 1024) or KBMB, … (powers of 1000).


du command:

du command – Display the amount of disk space used by the specified files and for each subdirectory.

Syntax: du

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

Options

-a–allWrite counts for all files, not just directories.
–apparent-sizePrint 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, and indirect blocks.
-B–block-size=SIZEScale sizes by SIZE before printing them. For example, ‘-BM‘ prints sizes in units of 1,048,576 bytes. (See SIZE format below).
-b–bytesEquivalent to ‘–apparent-size –block-size=1‘.
-c–totalDisplay a grand total.
-D–dereference-argsDereference only symlinks that are listed on the command line. ( The dereference operator or indirection operator, sometimes denoted by “*” (i.e. an asterisk), is a unary operator (i.e. one with a single operand) found in C-like languages that include pointer variables. )
–files0-from=FSummarize disk usage of the NUL-terminated file names specified in file F; If F is “” then read names from standard input.
-HEquivalent to –dereference-args (-D).
-h–human-readablePrint sizes in human readable format, rounding values and using abbreviations. For example, “1K”, “234M”, “2G”, etc.
–siLike -h, but use powers of 1000, not 1024.
-kLike –block-size=1K.
-l–count-linksCount sizes many times if hard-linked.
-mLike –block-size=1M.
-L–dereferenceDereference all symbolic links.
-P–no-dereferenceDon’t follow any symbolic links (this is the default).
-0–nullEnd each output line with 0 byte rather than newline.
-S–separate-dirsDo not include size of subdirectories.
-s–summarizeDisplay only a total for each argument.
-x–one-file-systemSkip directories on different file systems.
-X–exclude-from=FILEExclude files that match any pattern in FILE.
–exclude=PATTERNExclude files that match PATTERN.
-d–max-depth=NPrint the total for a directory (or file, with –all) only if it is N or fewer levels below the command line argument; –max-depth=0 is the same as –summarize.
–timeShow time of the last modification of any file in the directory, or any of its subdirectories.
–time=WORDShow time as WORD instead of modification time: atimeaccessusectime or status.
–time-style=STYLEShow times using style STYLE: full-isolong-isoiso, or +FORMAT. (FORMAT is interpreted like the format of ‘date‘.)
–helpDisplay a help message and exit.
–versionOutput version information and exit.

SIZE Format

Display values are in units of the first available SIZE from –block-size, and the DU_BLOCK_SIZEBLOCK_SIZE and BLOCKSIZE environment variables. Otherwise, units default to 1024 bytes (or 512 if POSIXLY_CORRECT is set).

SIZE is an integer and optional unit (example: 10M is 10*1024*1024). Units are K, M, G, T, P, E, Z, Y (powers of 1024) or KBMB, … (powers of 1000).

Advertisements

One thought on “linux – df and du

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.