How to check free disk space in Linux Ubuntu. How to use df and du commands in Ubuntu Linux to check disk space in gb. Use these commands to check hard disk space via Ubuntu command line.
Using df Command
‘df’ reports the amount of disk space used and available on file systems. With no arguments, ‘df’ reports the space used and available on all currently mounted file systems (of all types). Otherwise, ‘df’ reports on the file system containing each argument FILE.
Normally the disk space is printed in units of 1024 bytes, but this can be overridden (*note Block size::). For bind mounts and without arguments, ‘df’ only outputs the statistics for that device with the shortest mount point name in the list of file systems (MTAB), i.e., it hides duplicate entries, unless the ‘-a’ option is specified.
Method 1
df -h shows disk space in human-readable format
‘-h’ or ‘–human-readable’ – Append a size letter to each size, such as ‘M’ for mebibytes. Powers of 1024 are used, not 1000; ‘M’ stands for 1,048,576 bytes. This option is equivalent to ‘–block-size=human-readable’. Use the ‘–si’ option if you prefer powers of 1000.
Method 2
df -a shows the file system’s complete disk usage even if the Available field is 0
‘-a’ or ‘–all’ – Include in the listing dummy, duplicate, or inaccessible file systems, which are omitted by default. Dummy file systems are typically special purpose pseudo file systems such as ‘/proc’, with no associated storage.
Duplicate file systems are local or remote file systems that are mounted at separate locations in the local file hierarchy, or bind mounted locations. Inaccessible file systems are those which are mounted but subsequently over-mounted by another file system at that point, or otherwise inaccessible due to permissions of the mount point etc.
Method 3
df -T shows the disk usage along with each block’s filesystem type (e.g., xfs, ext2, ext3, btrfs, etc.)
‘-T’ or ‘–print-type’ – Print each file system’s type. The types printed here are the same ones you can include or exclude with ‘-t’ and ‘-x’. The particular types printed are whatever is supported by the system.
Here are some of the common names (this list is certainly not exhaustive):
- ‘nfs’ – An NFS file system, i.e., one mounted over a network from another machine. This is the one type name which seems to be used uniformly by all systems.
- ‘ext2, ext3, ext4, xfs, btrfs…’ – A file system on a locally-mounted hard disk. (The system might even support more than one type here; Linux does.)
- ‘ntfs,fat’ – File systems used by MS-Windows / MS-DOS.
Using du Command
‘du’ reports the amount of disk space used by the set of specified files and for each subdirectory (of directory arguments). With no arguments, ‘du’ reports the disk space for the current directory. Normally the disk space is printed in units of 1024 bytes, but this can be overridden (*note Block size::).
If two or more hard links point to the same file, only one of the hard links is counted. The FILE argument order affects which links are counted, and changing the argument order may change the numbers and
entries that ‘du’ outputs.
Method 1
du -h shows disk usage in human-readable format for all directories and subdirectories
‘-h’ or ‘–human-readable’ – Append a size letter to each size, such as ‘M’ for mebibytes. Powers of 1024 are used, not 1000; ‘M’ stands for 1,048,576 bytes. This option is equivalent to ‘–block-size=human-readable’. Use the ‘–si’ option if you prefer powers of 1000.
Method 2
du -a shows disk usage for all files even when that output would contain data with embedded newlines.
‘-a’ or ‘–all’ – Show counts for all files, not just directories.
Method 3
du -s provides total disk space used by a particular file or directory
‘-s’ or ‘–summarize’ – Display only a total for each argument.
Using fdisk Command
fdisk is a dialog-driven program for creation and manipulation of partition tables. It understands GPT, MBR, Sun, SGI and BSD parti‐ tion tables.
Method 1
fdisk -l shows disk size along with disk partitioning information
-l, –list – List the partition tables for the specified devices and then exit. If no devices are given, those mentioned in /proc/partitions (if that file exists) are used.