• news
  • pics
  • linux
  • windows
  • proxmox
  • game
  • news
  • pics
  • linux
  • windows
  • proxmox
  • game
Home
linux

Linux Check Disk Space Command To View System Disk Usage

recently switched from a Windows server to a Linux server operating system and need Linux check disk space command. I am using Ubuntu LTS 16.04 and CentOS 7.x server. How do I find out disk space utilization information using command line option?

Linux offer the following commands to check disk space

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 ##

Summary For Linux Check Disk Space Commands

Use du command when you need to estimate file space usage. To report file system disk space usage use the df command. btrfs df must be used when using btrfs file system. 

Previous article 【COS】黑saber
Next article How to Kill a Process from the Command Line

therock

14 Comments

  1. keto vegan recipes
    July 7, 2021 at 1:08 pm

    keto diet sample menu

  2. how many carbs a day on the keto diet
    July 7, 2021 at 11:00 am

    how to start keto

  3. keto diet schedule
    July 7, 2021 at 9:14 am

    whey protein on keto diet

  4. free transexual dating sites
    June 26, 2021 at 6:37 pm

    free thai dating online

  5. free tranny dating florida
    June 25, 2021 at 3:13 pm

    free online dating site in greece

  6. 100 free us dating sites
    June 24, 2021 at 9:41 pm

    yahoo dating free

  7. totally free catholic dating sites
    June 2, 2021 at 9:28 am

    zoosk dating free search

  8. western dating sites free
    June 2, 2021 at 8:38 am

    italian singles free dating

  9. free muslim dating uk
    May 27, 2021 at 12:31 am

    number 1 dating site free

  10. free dating site on mobile
    May 21, 2021 at 1:56 am

    free dating websites for kids

  11. free 14 year old dating site
    May 20, 2021 at 11:59 pm

    free asexual dating sites

  12. free hippie dating site
    May 20, 2021 at 6:35 pm

    free online lesbian dating sites

  13. free dating site for women
    May 19, 2021 at 10:36 pm

    free dating site in new zealand

  14. tinder like brent
    May 15, 2021 at 2:16 pm

    tinder like brent

    Linux Check Disk Space Command To View System Disk Usage – rock funs

Meta
  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
Categories
  • game
  • linux
  • news
  • pics
  • proxmox
  • windows
Recent Posts
  • proxmox7.3直通显卡
  • Proxmox VE 直通显卡方案及解决N卡Code43
  • Linux系统出现:You have new mail in /var/spool/mail/root 的原因及解决办法
  • debian系统解决中文乱码
  • pve添加git和pvetools
Recent Comments
  • EdgarTot on proxmox7.3直通显卡
  • Ashvem on proxmox7.3直通显卡
  • Tedvem on proxmox7.3直通显卡
  • Jackvem on proxmox7.3直通显卡
  • Miavem on proxmox7.3直通显卡
Archives
  • March 2023 (1)
  • December 2022 (4)
  • November 2022 (6)
  • April 2022 (1)
  • February 2022 (5)
  • January 2022 (2)
  • December 2021 (3)
  • November 2021 (1)
  • October 2021 (2)
  • September 2021 (1)
  • August 2021 (1)
  • July 2021 (8)
  • June 2021 (14)
  • May 2021 (2)
  • April 2021 (2)
  • March 2021 (10)
  • January 2021 (4)
  • December 2020 (4)
  • November 2020 (13)
  • April 2020 (276)
  • March 2020 (1)
  • June 2019 (5)
  • May 2019 (10)
  • December 2015 (1)