Skip to main content

Linux Check Disk Space Command To View System Disk Usage

Linux command to check disk space using:

  1. df command – Shows the amount of disk space used and available on Linux file systems.
  2. du command – Display the amount of disk space used by the specified files and for each subdirectory.
  3. btrfs fi df /device/ – Show disk space usage information for a btrfs based mount point/file system.

Linux check disk space with df command

  1. Open the terminal and type the following command to check disk space.
  2. The basic syntax for df is:
    df [options] [devices]
    Type:
  3. df
  4. df -H
Sample outputs:
Fig.01: linux check disk space with df command
Fig.01: df command in action

The items in square brackets are optional. You can simply type the df command (i.e. no arguments), to see a table that lists for each device name on the system.

See information about specific filesystem

You can give a device or mount point as an argument, and df report data only for the filesystem physically residing on that device. For example, the following command provides information only for the partition /dev/sda:
$ df /dev/sda
$ df -h /dev/sdc1
$ df /data/

Sample outputs:
Filesystem      1K-blocks     Used  Available Use% Mounted on
/dev/sda       2930266584 69405248 2859579472   3% /data

UNDERSTANDING DF COMMAND OUTPUT

The valid fields are as follows:
Display nameValid field name (for --output option)Description
FilesystemsourceThe source of the mount point, usually a device.
1K-blockssizeTotal number of blocks.
UsedusedNumber of used blocks.
AvailableavailNumber of available blocks.
Use%pcentPercentage of USED divided by SIZE.
Mounted ontargetThe mount point.
You can pass the output format defined by ‘valid field name’ as follows:
$ df --output=field1,field2,...
$ df --output=source,used,avail /data/

Sample outputs:
Filesystem                    Used Avail
/dev/md0                      5.4G  115G
udev                             0   11M
tmpfs                         6.2M  414M
tmpfs                         4.1k  1.1G
tmpfs                         4.1k  5.3M
tmpfs                            0  1.1G
/dev/md2                      818G  688G
tmpfs                            0  210M
tmpfs                            0  210M
/dev/mapper/cryptvg-mybackup   77G  526G
You can print all available fields, enter:
$ df --o
Sample outputs:
Filesystem     Type     Inodes  IUsed  IFree IUse%  1K-blocks     Used      Avail Use% File Mounted on
udev           devtmpfs 379248    333 378915    1%      10240        0      10240   0% -    /dev
tmpfs          tmpfs    381554    498 381056    1%     610488     9704     600784   2% -    /run
/dev/sdc1      ext3     956592 224532 732060   24%   14932444  7836056    6331204  56% -    /
tmpfs          tmpfs    381554      1 381553    1%    1526216        0    1526216   0% -    /dev/shm
tmpfs          tmpfs    381554      4 381550    1%       5120        0       5120   0% -    /run/lock
tmpfs          tmpfs    381554     14 381540    1%    1526216        0    1526216   0% -    /sys/fs/cgroup
/dev/sda       btrfs         0      0      0     - 2930266584 69405248 2859579472   3% -    /data
tmpfs          tmpfs    381554      4 381550    1%     305244        0     305244   0% -    /run/user/0

Express df output in human readable form

Pass the -h option to see output in human readable format. You will device size in gigabytes or terabytes or megabytes:
$ df -h ### Human format
$ df -m ### Show output size in one-megabyte
$ df -k ### Show output size in one-kilobyte blocks (default)

Display output using inode usage instead of block usage

An inode is a data structure on a Linux file system that stores all information about file. To list inode information, enter:
$ df -i
$ df -i -h

Sample outputs:
Filesystem     Inodes IUsed IFree IUse% Mounted on
udev             371K   333  371K    1% /dev
tmpfs            373K   498  373K    1% /run
/dev/sdc1        935K  220K  715K   24% /
tmpfs            373K     1  373K    1% /dev/shm
tmpfs            373K     4  373K    1% /run/lock
tmpfs            373K    14  373K    1% /sys/fs/cgroup
/dev/sda            0     0     0     - /data
tmpfs            373K     4  373K    1% /run/user/0

Find out the type of each file system displayed

Pass the -T option to display the type of each filesystems listed such as ext4, btrfs, ext2, nfs4, fuse, cgroup, cputset, and more:
$ df -T
$ df -T -h
$ df -T -h /data/

Sample outputs:
Filesystem     Type   Size  Used Avail Use% Mounted on
/dev/sda       btrfs  2.8T   67G  2.7T   3% /data

Limit listing to file systems of given type

The syntax is:
$ df -t ext3 #Only see ext3 file system
$ df -t ext4 #Only see ext4 file system
$ df -t btrfs #Only see btrfs file system

Exclude given file system type

To list all but exclude ext2 filesystem pass the -x TYPE option, enter:
$ df -x ext2

Show all file system

Pass the -a or --all option to the df command to include in its output filesystems that have a size of zero blocks, run:
$ df -a
Filesystem      1K-blocks     Used  Available Use% Mounted on
sysfs                   0        0          0    - /sys
proc                    0        0          0    - /proc
udev                10240        0      10240   0% /dev
devpts                  0        0          0    - /dev/pts
tmpfs              610488     9708     600780   2% /run
/dev/sdc1        14932444  7836084    6331176  56% /
securityfs              0        0          0    - /sys/kernel/security
tmpfs             1526216        0    1526216   0% /dev/shm
tmpfs                5120        0       5120   0% /run/lock
tmpfs             1526216        0    1526216   0% /sys/fs/cgroup
cgroup                  0        0          0    - /sys/fs/cgroup/systemd
pstore                  0        0          0    - /sys/fs/pstore
cgroup                  0        0          0    - /sys/fs/cgroup/cpuset
cgroup                  0        0          0    - /sys/fs/cgroup/cpu,cpuacct
cgroup                  0        0          0    - /sys/fs/cgroup/blkio
cgroup                  0        0          0    - /sys/fs/cgroup/memory
cgroup                  0        0          0    - /sys/fs/cgroup/devices
cgroup                  0        0          0    - /sys/fs/cgroup/freezer
cgroup                  0        0          0    - /sys/fs/cgroup/net_cls,net_prio
cgroup                  0        0          0    - /sys/fs/cgroup/perf_event
systemd-1               -        -          -    - /proc/sys/fs/binfmt_misc
fusectl                 0        0          0    - /sys/fs/fuse/connections
debugfs                 0        0          0    - /sys/kernel/debug
mqueue                  0        0          0    - /dev/mqueue
hugetlbfs               0        0          0    - /dev/hugepages
/dev/sda       2930266584 69405248 2859579472   3% /data
rpc_pipefs              0        0          0    - /run/rpc_pipefs
tmpfs              305244        0     305244   0% /run/user/0
binfmt_misc             0        0          0    - /proc/sys/fs/binfmt_misc
These file systems omitted by default.

Getting more help about the df command

Pass the --help option see a brief help message:
$ df --help
Or read its man page by typing the following command:
$ man df

Linux check disk space with the du command

The du command is very useful to track down disk space hogs. It is useful to find out the names of directories and files that consume large amounts of space on a disk. The basic syntax is:
du
du /path/do/dir
du [options] [directories and/or files]

To see the names and space consumption of each of the directories including all subdirectories in the directory tree, enter:
$ du
Sample outputs:
16 ./.aptitude
12 ./.ssh
56 ./apcupsd
8 ./.squidview
4 ./kernel.build
12 ./.elinks
8 ./.vim
8 ./.config/htop
12 ./.config
648 .
The first column is expressed in kilobytes (file size) and the second column is the filename or directory name.

See du output in human readable format

Pass the -h option to display size in K (kilobytes), M (megabytes), G (gigabytes) instead of the default kilobytes:
$ du -h
Sample outputs:
16K ./.aptitude
12K ./.ssh
56K ./apcupsd
8.0K ./.squidview
4.0K ./kernel.build
12K ./.elinks
8.0K ./.vim
8.0K ./.config/htop
12K ./.config
648K .

Finding information about any directory trees or files

To find out /etc/ directory space usage, enter:
# du /etc/
# du -h /etc/

The following will report the sizes of the thee files named hdparm, iptunnel and ifconfig that are located in the /sbin directory:
$ du /sbin/hdparm /sbin/iptunnel /sbin/ifconfig
$ du -h /sbin/hdparm /sbin/iptunnel /sbin/ifconfig

Sample outputs:
112K /sbin/hdparm
24K /sbin/iptunnel
72K /sbin/ifconfig

How do I summarize disk usage for given directory name?

Pass the -s option to the du command. In this example, ask du command to report only the total disk space occupied by a directory tree and to suppress subdirectories:
# du -s /etc/
# du -sh /etc/

Sample outputs:
6.3M /etc/
Pass the -a (all) option to see all files, not just directories:
# du -a /etc/
# du -a -h /etc/

Sample outputs:
4.0K /etc/w3m/config
4.0K /etc/w3m/mailcap
12K /etc/w3m
4.0K /etc/ConsoleKit/run-seat.d
4.0K /etc/ConsoleKit/seats.d/00-primary.seat
8.0K /etc/ConsoleKit/seats.d
4.0K /etc/ConsoleKit/run-session.d
20K /etc/ConsoleKit
...
....
..
...
4.0K /etc/ssh/ssh_host_rsa_key
4.0K /etc/ssh/ssh_host_rsa_key.pub
4.0K /etc/ssh/ssh_host_dsa_key
244K /etc/ssh/moduli
4.0K /etc/ssh/sshd_config
272K /etc/ssh
4.0K /etc/python/debian_config
8.0K /etc/python
0 /etc/.pwd.lock
4.0K /etc/ldap/ldap.conf
8.0K /etc/ldap
6.3M /etc/
You can also use star ( * ) wildcard, which will match any character. For example, to see the size of each png file in the current directory, enter:
$ du -ch *.png
 52K CIQTK4FUAAAbjDw.png-large.png
 68K CX23RezWEAA0QY8.png-large.png
228K CY32cShWkAAaNLD.png-large.png
 12K CYaQ3JqU0AA-amA.png-large.png
136K CYywxDfU0AAP2py.png
172K CZBoXO1UsAAw3zR.png-large.png
384K Screen Shot 2016-01-19 at 5.49.21 PM.png
324K TkamEew.png
8.0K VQx6mbH.png
 64K fH7rtXE.png
 52K ipv6-20-1-640x377.png
392K unrseYB.png
1.8M total
The -c option tells du to display grand total.

Putting it all together

To list top 10 directories eating disk space in /etc/, enter:
# du -a /etc/ | sort -n -r | head -n 10
Sample outputs:
8128 /etc/
928 /etc/ssl
904 /etc/ssl/certs
656 /etc/apache2
544 /etc/apache2/mods-available
484 /etc/init.d
396 /etc/php5
336 /etc/sane.d
308 /etc/X11
268 /etc/ssl/certs/ca-certificates.crt
For more information on the du command, type:
$ man du
$ du --help

Dealing with btrfs file system

For btrfs filesystem use the btrfs fi df command to see space usage information for a mount point. The syntax is:
btrfs filesystem df /path/
btrfs fi df /dev/path
btrfs fi df [options] /path/

Examples

# btrfs fi df /data/
# btrfs fi df -h /data/

Sample outputs:
Data, RAID1: total=71.00GiB, used=63.40GiB
System, RAID1: total=8.00MiB, used=16.00KiB
Metadata, RAID1: total=4.00GiB, used=2.29GiB
GlobalReserve, single: total=512.00MiB, used=0.00B
To see raw numbers in bytes, run:
# btrfs fi df -b /data/
OR
# btrfs fi df -k /data/ ### show sizes in KiB ##
# btrfs fi df -m /data/ ### show sizes in MiB ##
# btrfs fi df -g /data/ ### show sizes in GiB ##
# btrfs fi df -t /data/ ### show sizes in TiB ##

Popular posts from this blog

How to read or extract text data from passport using python utility.

Hi ,  Lets get start with some utility which can be really helpful in extracting the text data from passport documents which can be images, pdf.  So instead of jumping to code directly lets understand the MRZ, & how it works basically. MRZ Parser :                 A machine-readable passport (MRP) is a machine-readable travel document (MRTD) with the data on the identity page encoded in optical character recognition format Most travel passports worldwide are MRPs.  It can have 2 lines or 3 lines of machine-readable data. This method allows to process MRZ written in accordance with ICAO Document 9303 (endorsed by the International Organization for Standardization and the International Electrotechnical Commission as ISO/IEC 7501-1)). Some applications will need to be able to scan such data of someway, so one of the easiest methods is to recognize it from an image file. I 'll show you how to retrieve the MRZ infor...

How to generate class diagrams pictures in a Django/Open-edX project from console

A class diagram in the Unified Modeling Language ( UML ) is a type of static structure diagram that describes the structure of a system by showing the system’s classes, their attributes, operations (or methods), and the relationships among objects. https://github.com/django-extensions/django-extensions Step 1:   Install django extensions Command:  pip install django-extensions Step 2:  Add to installed apps INSTALLED_APPS = ( ... 'django_extensions' , ... ) Step 3:  Install diagrams generators You have to choose between two diagram generators: Graphviz or Dotplus before using the command or you will get: python manage.py graph_models -a -o myapp_models.png Note:  I prefer to use   pydotplus   as it easier to install than Graphviz and its dependencies so we use   pip install pydotplus . Command:  pip install pydotplus Step 4:  Generate diagrams Now we have everything installed...

How to Remove course from Open-edX

Go to vagrant  => 1. In the edx-platform directory:  - cd /edx/app/edxapp/edx-platform 2. Run the following Django management command:   - sudo -u www-data /edx/bin/python.edxapp /edx/bin/manage.edxapp lms dump_course_ids --settings aws    - sudo -u www-data /edx/bin/python.edxapp /edx/bin/manage.edxapp lms dump_course_ids --settings=devstack 3. Find the course ID which you'd like to delete in the resulting list of course IDs. 4. Copy the course ID into the following command and run it:  - sudo -u www-data /edx/bin/python.edxapp /edx/bin/manage.edxapp cms delete_course <COURSE_ID> --settings aws  -   sudo -u www-data /edx/bin/python.edxapp /edx/bin/manage.edxapp cms delete_course <COURSE_ID> --settings=devstack  - You'll be asked to verify the deletion . To verify the deletion, run the command from step 2 above and ensure that the course ID is not in the list. Help reference : ...