Loading...
General

Using df to Show Disk Space Usage in Linux

To display the disk space usage for your drives in Linux, you are able to use the df command.  By default, it will show the usage of all the mounted drives in 1k blocks.  If the POSIXLY_CORRECT environment variable is set though, it will show in 512 byte blocks by default.  Below shows the command run with no options.


chris@Desktop:~$ df
Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/sdc1      575758492 126365356 420575064  24% /
udev             1538192        12   1538180   1% /dev
tmpfs             619612      1088    618524   1% /run
none                5120         0      5120   0% /run/lock
none             1549020       144   1548876   1% /run/shm

I personally like to use the -h flag with it, which will show the space in human readable format, in KB and GB.


chris@Desktop:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sdc1       550G  121G  402G  24% /
udev            1.5G   12K  1.5G   1% /dev
tmpfs           606M  1.1M  605M   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            1.5G  144K  1.5G   1% /run/shm

The -a flag will show all of the file systems, including dummy file systems.

chris@Desktop:~$ df -a
Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/sdc1      575758492 126365360 420575060  24% /
proc                   0         0         0    - /proc
sysfs                  0         0         0    - /sys
none                   0         0         0    - /sys/fs/fuse/connections
none                   0         0         0    - /sys/kernel/debug
none                   0         0         0    - /sys/kernel/security
udev             1538192        12   1538180   1% /dev
devpts                 0         0         0    - /dev/pts
tmpfs             619612      1088    618524   1% /run
none                5120         0      5120   0% /run/lock
none             1549020       144   1548876   1% /run/shm
binfmt_misc            0         0         0    - /proc/sys/fs/binfmt_misc
rpc_pipefs             0         0         0    - /run/rpc_pipefs
nfsd                   0         0         0    - /proc/fs/nfsd

Using df with the –total flag will show the drive spaces as well. The total space of all the drives together.

chris@Desktop:~$ df -h --total
Filesystem      Size  Used Avail Use% Mounted on
/dev/sdc1       550G  121G  402G  24% /
udev            1.5G   12K  1.5G   1% /dev
tmpfs           606M  1.1M  605M   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            1.5G  144K  1.5G   1% /run/shm
total           553G  121G  405G  23%

Using the -i flag will show the number of inodes on the drives.  Inodes are the number of files and directories the disk contains.

chris@Desktop:~$ df -i
Filesystem       Inodes  IUsed    IFree IUse% Mounted on
/dev/sdc1      36028416 525729 35502687    2% /
udev             210007    628   209379    1% /dev
tmpfs            215421    607   214814    1% /run
none             215421      5   215416    1% /run/lock
none             215421      4   215417    1% /run/shm

The -T flag can also be added to show the filesystem type, such as ext3 or NTFS.

chris@Desktop:~$ df -T
Filesystem     Type     1K-blocks      Used Available Use% Mounted on
/dev/sdc1      ext4     575758492 126365408 420575012  24% /
udev           devtmpfs   1538192        12   1538180   1% /dev
tmpfs          tmpfs       619612      1088    618524   1% /run
none           tmpfs         5120         0      5120   0% /run/lock
none           tmpfs      1549020       144   1548876   1% /run/shm

The df command also has a couple other options, but I won’t be covering those today since the aren’t usually needed regularly.  The help info for the df command is below for reference.

Usage: df [OPTION]... [FILE]...20         0      5120   0% /run/lockShow information about the file system on which each FILE resides,
or all file systems by default.

Mandatory arguments to long options are mandatory for short options too.

-a, --all             include dummy file systems
-B, --block-size=SIZE  scale sizes by SIZE before printing them.  E.g.,
`-BM' prints sizes in units of 1,048,576 bytes.
See SIZE format below.
--total           produce a grand total
-h, --human-readable  print sizes in human readable format (e.g., 1K 234M
-H, --si              likewise, but use powers of 1000 not 1024
-i, --inodes          list inode information instead of block usage
-k                    like --block-size=1K
-l, --local           limit listing to local file systems
--no-sync         do not invoke sync before getting usage info (defau
-P, --portability     use the POSIX output format
--sync            invoke sync before getting usage info
-t, --type=TYPE       limit listing to file systems of type TYPE
-T, --print-type      print file system type
-x, --exclude-type=TYPE   limit listing to file systems not of type TYPE
-v                    (ignored)
--help     display this help and exit
--version  output version information and exit

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 may be (or may be an integer optionally followed by) one of following:
KB 1000, K 1024, MB 1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y.

Report df bugs to bug-coreutils@gnu.org

GNU coreutils home page:

General help using GNU software:

For complete documentation, run: info coreutils 'df invocation'



Know some other things you can do with the df command?  Tell us about it in the comments!

Popular Posts
  • No Popular Post Available
Leave a Reply

Your email address will not be published. Required fields are marked *

*