Monitoring disk usage
Disk space is always a limited resource. We monitor disk usage to know when it's running low, then search for large files or folders to delete, move, or compress. This recipe illustrates disk monitoring commands.
Getting ready
The du
(disk usage) and df
(disk free) commands report disk usage. These tools report what files and folders are consuming disk space and how much space is available.
How to do it...
To find the disk space used by a file (or files), use the following command:
$ du FILENAME1 FILENAME2 ..
Consider this example:
$ du file.txt
To obtain the disk usage for all files inside a directory, along with the individual disk usage for each file shown in each line, use this command:
$ du -a DIRECTORY
The -a
option outputs results for all files in the specified directory or directories recursively.
Note
Running du DIRECTORY
will output a similar result, but it will show only the size consumed by subdirectories. However, this does not show the disk usage for each of the...