Wednesday, February 13, 2019

How to Check Disk Space in Linux Using the df Command

https://linuxize.com/post/how-to-check-disk-space-in-linux-using-the-df-command

How much space do I have left on my hard drive? Is there enough free disk space to download a large file or install a new application?
On Linux based systems you can use the df command to get a detailed report on the system’s disk space usage.
When used without any argument, the df command will display information about all mounted file systems:
df
Copy
Filesystem     1K-blocks      Used Available Use% Mounted on
dev              8172848         0   8172848   0% /dev
run              8218640      1696   8216944   1% /run
/dev/nvme0n1p3 222284728 183057872  27865672  87% /
tmpfs            8218640    150256   8068384   2% /dev/shm
tmpfs            8218640         0   8218640   0% /sys/fs/cgroup
tmpfs            8218640        24   8218616   1% /tmp
/dev/nvme0n1p1    523248    107912    415336  21% /boot
/dev/sda1      480588496 172832632 283320260  38% /data
tmpfs            1643728        40   1643688   1% /run/user/1000
Copy
Each line includes information about the file system name (Filesystem), the size (1K-blocks), the used space (Used), the available space (Available), the percentage of used space (Use%), and the directory in which the filesystem is mounted (Mounted on).
To display information only for a specific file system pass the filesystem name or the mount point to the df command. For example to show the space available on the file system mounted to system root directory / you can use either df /dev/nvme0n1p3 or df /.
df /
Copy
Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/nvme0n1p3 222284728 183057872  27865672  87% /
Copy
By default, the df command shows the disk space in 1 kilobyte blocks and the size of used and available disk space in kilobytes. To view the information human-readable format (megabytes and gigabytes), pass the -h option:
df -h
Copy
Filesystem     1K-blocks      Used Available Use% Mounted on
Filesystem      Size  Used Avail Use% Mounted on
dev             7.8G     0  7.8G   0% /dev
run             7.9G  1.8M  7.9G   1% /run
/dev/nvme0n1p3  212G  176G   27G  88% /
tmpfs           7.9G  145M  7.7G   2% /dev/shm
tmpfs           7.9G     0  7.9G   0% /sys/fs/cgroup
tmpfs           7.9G   24K  7.9G   1% /tmp
/dev/nvme0n1p1  511M  106M  406M  21% /boot
/dev/sda1       459G  165G  271G  38% /data
tmpfs           1.6G   16K  1.6G   1% /run/user/1000
Copy
To display file system types, use the df command followed the -T option:
df -t
Copy
Filesystem     Type     1K-blocks      Used Available Use% Mounted on
dev            devtmpfs   8172848         0   8172848   0% /dev
run            tmpfs      8218640      1744   8216896   1% /run
/dev/nvme0n1p3 ext4     222284728 183666100  27257444  88% /
tmpfs          tmpfs      8218640    383076   7835564   5% /dev/shm
tmpfs          tmpfs      8218640         0   8218640   0% /sys/fs/cgroup
tmpfs          tmpfs      8218640        24   8218616   1% /tmp
/dev/nvme0n1p1 vfat        523248    107912    415336  21% /boot
/dev/sda1      ext4     480588496 172832632 283320260  38% /data
tmpfs          tmpfs      1643728        40   1643688   1% /run/user/1000
Copy
If you want to limit listing to file systems of a specific type use the -t option followed by the type. For example to list all ext4 partitions you would run:
df -t ext4
Copy
Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/nvme0n1p3 222284728 183666112  27257432  88% /
/dev/sda1      480588496 172832632 283320260  38% /data
Copy
Similar to above, the -x option allows you to limit the output to file systems that are not of a specific type,
When used with the -i option the df command will display information about the filesystem inodes usage. For example to show information about the inodes on the file system mounted to system root directory / in human-readable format you would use:
df -ih /
Copy
Filesystem     Inodes IUsed IFree IUse% Mounted on
/dev/nvme0n1p3    14M  1.9M   12M   14% /
Copy
An inode is a data structure in a Unix and Linux file systems, which contains information about a file or directory such as its size, owner, device node, socket, pipe, etc., except da.
The df command also allows you to specify the output format.
To limit the reported fields shown in the df output use the --output[=FIELD_LIST] option. FIELD_LIST is a comma-separated list of columns to be included in the output. Each field can be used only once. Valid field names are:
  • source - The File system source.
  • fstype - The File system type.
  • itotal - Total number of inodes.
  • iused - Number of the used inodes.
  • iavail - Number of the available inodes.
  • ipcent - Percentage of used inodes.
  • size - Total disk space.
  • used - Used disk space.
  • avail - Available disk space.
  • pcent - Percentage of used space.
  • file - The file name if specified on the command line.
  • target - The mount point.
For example to display the output of all ext4 partition in human-readable format, showing only the filesystem name and size and the percentage of the used space you would use:
df -h -t ext4 --output=source,size,pcent
Copy
Filesystem      Size Use%
/dev/nvme0n1p3  212G  88%
/dev/sda1       459G  38%
Copy
By now you should have a good understanding of how to use the df command. You can always view all available df command options by typing man df in your terminal.

No comments:

Post a Comment