Monitoring disk usage
Disk space is a limited resource. We frequently perform disk usage calculation on storage media (such as hard disks) to find out the free space available on them. When free space becomes scarce, we find out large files to be deleted or moved in order to create free space. In addition to this, disk usage manipulations are also used in shell scripting contexts. This recipe will illustrate various commands used for disk manipulations with a variety of options.
Getting ready
df
and
du
are the two significant commands that are used for calculating disk usage in Linux. The command df
stands for disk free and du
stands for disk usage. Let's see how we can use them to perform various tasks that involve disk usage calculation.
How to do it...
To find the disk space used by a file (or files), use:
$ du FILENAME1 FILENAME2 ..
For example:
$ du file.txt 4
Note
The result is, by default, shown as size in bytes.
To obtain the disk usage for all files inside a directory along with the...