
the df
and du
Commands report disk space usage from the bash shell used in Linux, macOS and many other Unix-like operating systems. These commands allow you to easily identify what is consuming your system storage.
Viewing total disk space, available and used
Bash contains two useful commands related to disk space. To find out the available and used disk space, use df
(disk file systems, sometimes called free disk). To find out what is taking up the used disk space, use du
(disk usage).
Writes df
and hit enter in a Bash terminal window to start. You will see a lot of results similar to the screenshot below. Using df
without any option it will show the available and used space for all mounted filesystems. At first sight, may seem impenetrable, but it is quite simple to understand.
df
Each line on the screen is made up of six columns.
- File System: The name of this file system.
- 1K blocks: The number of 1K blocks that are available on this file system.
- Use: The number of 1K blocks that have been used in this file system.
- Available: The number of 1K blocks that are not used in this file system.
- Use%: The amount of space used on this file system expressed as a percentage.
- Proceedings: The name of the file system, if specified on the command line.
- Mounted on: The file system mount point.
You can replace the 1K block counts with a more useful output using the -B
(block size) option. To use this option, scribe df,
a space, and then -B
and a letter from the list of K, M, G, T, P, E, Z o Y. These letters represent the values of kilo, mega, giga, tera, map, exa, zeta and yotta of the multiple of the scale 1024 .
As an example, to see disk usage figures in megabytes, I would use the following command. Note that there is no space between B and M.
df -BM
the -h
The option (human readable) instructs df
to use the most applicable drive for the size of each file system. At the next outing, notice that there are file systems with sizes of gigabytes, megabytes e inclusive kilobytes.
df -h
If you need to see the information represented in inode numbers, use el -i
(inodes) option. An inode is a data structure used by Linux file systems to describe files and store metadata about them. En Linux, inodes contain data like name, the modification date, the position on the hard drive, etc. for each file and directory. This will not be useful for most people., but system administrators sometimes need to query this kind of information.
df -i
Unless they tell you not to, df
will provide information about all mounted file systems. This can lead to a cluttered display with a lot of output. As an example, the /dev/loop
The entries in the lists are pseudo file systems that make it possible to mount a file as if it were a partition. If you use the new Ubuntu snap
application installation method, you can get many of these. The space available in these will always be 0 because they are not truly a filesystem, so we don't need to see them.
We can say df
to exclude file systems of a specific type. To do it, we need to know what type of filesystem we intend to exclude. the -T
The option (printing type) give us that information. Instructs df
to include the filesystem type in the output.
df -T
the /dev/loop
the entrances are all squashfs
file systems. We can exclude them with the following command:
df -x squashfs
That gives us a more manageable way out. To get a total, we can add the --total
option.
df -x squashfs --total
We can ask df
to include only filesystems of a particular type, using the -t
(kind) option.
df -t ext4
If we want to see the sizes of a set of filesystems, we can specify them by name. Drive names in Linux are alphabetical. The first unit is called /dev/sda
, the second unit is /dev/sdb
, and so on. The partitions are numbered. Then /dev/sda1
is the first partition on the drive /dev/sda
. We say df
to return information about a particular file system by passing the file system name as a command parameter. Let's look at the first partition of the first hard drive.
df /dev/sda1
Note that you can use wildcards in the file system name, where *
represents any set of characters and ?
represents any single character. Then, to see all partitions on the first drive, we could use:
df / dev / sda *
We can ask df
to report on a set of named file systems. He is requesting the sizes of the /dev
and /run
file systems, and we would like a total.
df -h --total /dev /run
To further personalize the display, we can say df
what columns to include. To do so use the --output
and provide a comma separated list of required column names. Make sure you don't include spaces in the comma separated listing.
- source: The name of the file system.
- fstype: The type of filesystem.
- itotal: The size of the filesystem in inodes.
- used to: The space used in the file system in inodes.
- iavail: The available space on the file system in inodes.
- ipcent: The percentage of space used on the file system in inodes, as a percentage.
- Size: The size of the file system, default in 1K blocks.
- use: The space used in the file system, default in 1K blocks.
- to take advantage of: The available space on the file system, default in 1K blocks.
- pcent: The percentage of space used on the file system in inodes, default in 1K blocks.
- proceedings: The file system name if specified on the command line.
- objective: The file system mount point.
Let's ask df
to report the first partition on the first drive, with human readable numbers and with source columns, fstype, size, used, avail y pcent:
df -h /dev/sda1 --output=source,fstype,size,used,avail,pcent
Long commands are perfect candidates to become an alias. We can create an alias dfc
(by df custom
) typing the following and hitting Enter:
alias dfc="df -h /dev/sda1 --output=source,fstype,size,used,avail,pcent"
Typing dfc
and hitting enter will have the same effect as typing the long command. For this alias to be permanent, add it to your .
O bashrc
.bash_aliases
proceedings.
We have been looking for alternatives to refine the output of df
so that the information it shows matches your requirements. If you want to take the opposite approach and have df
return all information that can be used by the -a
(everybody) the option and the --output
option as shown below. the -a
(everybody) the option asks df
to include all file systems, and using the --output
option without a comma separated list of columns causes df
to include all columns.
df -a --output
Channeling the output of df
through less
The command is a convenient way to review the large number of results it can produce.
df -a --output | less
Find out what is taking up the used disk space
Let's do some research and find out what's taking up space on this PC. We will start with one of our df
commands.
df -h -t ext4
It uses a 78% disk space on the first partition of the first hard drive. We can use the du
command to show which folders contain the most data. Issuing the du
The command without options will list all the directories and subdirectories under the directory du
The command was issued in. If you do this from your home folder, the list will be very long.
du
The output format is very easy. Each line shows the size and name of a directory. Default, size shown in 1K blocks. To force du
to use a different block size, use el -B
(block size) option. To use this type of option du
, a space, and then -B
and a letter from the list of K, M, G, T, P, E, Z e Y, as we did previously for df
. To use 1M blocks, use this command:
du -BM
In the same way that df
, du
has a human readable option, -h
, which uses a range of block sizes based on the size of each directory.
you h
the -s
The option (abstract) gives a total for each directory without showing the subdirectories within each directory. The following command asks du
to return information in summary format, in human readable numbers, for all directories
du -h -s *
Output of the du command with the -h -s alternatives * du
The image folder contains the most data by far. We can ask
du -sm Pictures/* | sort no
Output of the du command with the -sm Pictures command / *! sort -nr options df
By refining the information returned by du
and
It's easy to find out how much hard drive space is in use and what is taking up that space. Subsequently, you can make an informed choice about how to move some data to other storage, add another hard drive to your computer or erase redundant data. These commands have many options. Here we describe the most useful options, but you can see a full list of options for df command and for him du command
in Linux man pages.