Author: Dave McKay / Source: How-To Geek
The df
and du
commands report on disk space usage from within the Bash shell used on Linux, macOS, and many other Unix-like operating systems. These commands let you easily identify what’s using up your system’s storage.
Viewing the Total, Available and Used Disk Space
Bash contains two useful commands related to disk space. To find out the available and used disk space, use df
(disk filesystems, sometimes called disk free). To discover what’s taking up the used disk space, use du
(disk usage).
Type df
and press enter in a Bash terminal window to get started. You’ll see a lot of output similar to the screenshot below. Using df
without any options will display the available and used space for all mounted filesystems. At first glance, it might look impenetrable, but it is quite easy to understand.
df
Each line of the display is made up of six columns.
- Fileystem: The name of this filesystem.
- 1K-Blocks: The number of 1K blocks that are available on this filesystem.
- Used: The number of 1K blocks that have been used on this file system.
- Available: The number of 1K blocks that are unused on this file system.
- Use%: The amount of space used in this file system given as a percentage.
- File: The filesystem name, if specified on the command line.
- Mounted on: The mount point of the filesystem.
You can replace the 1K block counts with more useful output by using the -B
(block size) option. To use this option, type df,
a space, and then -B
and a letter from the list of K, M, G, T, P, E, Z or Y. These letters represent the kilo, mega, giga, tera, peta, exa, zeta, and yotta values from the multiple of 1024 scale.
For example, to see the disk usage figures in megabytes, you would use the following command. Note there is no space between the B and M.
df -BM
The -h
(human readable) option instructs df
to use the most applicable unit for the size of each filesystem. In the next output note that there are filesystems with gigabyte, megabyte and even kilobyte sizes.
df -h
If you need to see the information represented in numbers of inodes, use the -i
(inodes) option. An inode is a data structure used by Linux filesystems to describe files and to store metadata about them. On Linux, inodes hold data such as the name, modification date, position on the hard drive, and so on for each file and directory. This isn’t going to be useful to the majority of people, but system administrators must sometimes refer to this type of information.
df -i
Unless told not to, df
will provide information on all of the mounted file systems. This can lead to a cluttered display with a lot of output. For example, the /dev/loop
entries in the lists are pseudo file systems that allow a file to be mounted as though it were a partition. If you use the new Ubuntu snap
method of installing applications, you can acquire a lot of these. The space available on these will always be 0 because they aren’t really a filesystem, so we don’t need to see them.
We can tell df
to exclude filesystems of a specific type. To do so, we need to know what type of filesystem we wish to exclude. The -T
(print-type) option will give us that information. It instructs df
to include the type of filesystem in the output.
df -T
The /dev/loop
entries are all squashfs
filesystems. We can exclude them with the following command:
df -x squashfs
That gives us a more manageable output. To get a total, we can add the --total
option.
df -x squashfs --total
We can ask df
…
The post How to View Free Disk Space and Disk Usage From the Linux Terminal appeared first on FeedBox.