Find How Much Disk Space a File or Folder Uses in Linux

Manage hard drive space from the command line

This guide shows how to use the Linux command line to find out the amount of disk space a file or folder takes up.

Find Out the File Sizes of All Files and Folders

The du command summarises the disk usage of each file. In its simplest form, you can run the following command:


This scrolls through the files and folders in the present working directory. For each file that displays, the file size appears alongside it, and at the bottom, the total file size displays.

To find out how much space is used on the drive, start at the root folder by using the following command:

du /

You may need to use sudo along with the du command to elevate your permissions as follows:

sudo du /
Linux du command

The main issue with the above command is that it only lists the file size of the subfolders and not the files in those subfolders.

To get a complete listing, use one of the following commands:

du -a
du --all
Linux du command all

To get the output to scroll in pages, use the more command or the less command as follows:

du | more
du | less
Linux du command with less

Find out the File Size of Individual Files and Folders

When you want to find out the disk usage used by a single file, specify the file name along with the du command as follows:

du /path/to/file

For example:

du image.png

The output will be something like this:

36 image.png
Linux du single file

If you enter a folder name along with the du command, you get a list of all files in the folder. For example:

88 Steam/logs
92 Steam

The above shows that the Steam folder has a logs folder that has a size of 88, and the total for the Steam folder is 92.

It doesn't list the files in the logs folder. To get the list of files, use the following command:

du -a Steam

The results are now as follows:

84 Steam/logs/bootstrap_log.txt
88 Steam/logs
92 Steam
Linux du folder

Change the Output Of the File Size

By default, the file sizes are listed as kilobytes. You can change the block size to other values as follows:

du -BM

For example, a file called zorin.iso, which, by default, is 1630535680 in size.

du -BM zorin.iso

The above command outputs the size as 1556M.

Linux du units specified megabytes

You can also use K or G as follows:

du -BK zorin.iso
du -BG zorin.iso

In kilobytes, the zorin.iso file is listed as 159232K. In gigabytes, the zorin.iso file is listed as 2G.

There are eight possible settings, which are as follows:

  • K: Kilobytes
  • M: Megabytes
  • G: Gigabytes
  • T: Terabytes
  • P: Petabytes
  • E: Exabytes
  • Z: Zettabytes
  • Y: Yottabytes

If you get a list of files, getting the correct display size is difficult. For example, a file of 100 bytes needs to be displayed as bytes. A file that is 16 gigabytes is better shown in gigabytes.

To get the appropriate file size based on the file being displayed, use one of the following commands:

du -h
du --human-readable
Linux du human readable

Summarise the Output

To get the du command to show the total size of the files and folders, use the following commands:

du -c
du --total

You can also eliminate most of the other output, such as the listing of files and folders, by using the following commands:

du -s
du --summarize


You can find out more about the du command by running the man command in the terminal as follows:

man du

Another command you may wish to read about is the df command. This command reports the file system and disk space usage.


Was this page helpful?