Check used disk space on Linux with du

Find out how much disk space you're using with the Linux du command.
23 readers like this.
Check disk usage

CC BY-SA Seth Kenlon

No matter how much storage space you have, there's always the possibility for it to fill up. On most personal devices, drives get filled up with photos and videos and music, but on servers, it's not unusual for space to diminish due to data in user accounts and log files. Whether you're in charge of managing a multi-user system or just your own laptop, you can check in on disk usage with the du command.

By default, du provides the amount of disk space used in your current directory, as well as the size of each subdirectory:

$ du
12 ./.backups
60 .

In this example, my current directory takes up all of 60 KB, 12 KB of which is occupied by the subdirectory .backups.

If you find that confusing and would prefer to see all sizes separately, you can use the --separate-dirs (or -S for short) option:

$ du --separate-dirs
12 ./.backups
48 .

It's the same information (48 and 12 is 60) but each directory is treated independently of one another.

To see even more detail, use the --all (or -a for short) option, which displays each file in each directory:

$ du --separate-dirs --all                 
4       ./example.adoc
28      ./graphic.png
4       ./.backups/example.adoc~
12      ./.backups
4       ./index.html
4       ./index.adoc
48      .

See modification time of files

When looking through files to find out what's taking up space, it can be useful to see when a file was last modified. Something that hasn't been touched in a year is a likely candidate for archival, especially if you're running out of space.

To see modification times of files with du, use the --time option:

$ du --separate-dirs --all --time
28      2021-07-21 11:12        ./graphic.png
4       2021-07-03 10:43        ./example.adoc
4       2021-07-13 13:03        ./index.html
4       2021-07-23 14:18        ./index.adoc
48      2021-07-23 14:19        .

Set a threshold for file size

When reviewing files in the interest of disk space, you may only care about files of nontrivial size. You set a threshold for the file sizes you want to see with the --threshold (or -t for short) option. For instance, to view only sizes larger than 1 GB:

$ \du --separate-dirs --all --time --threshold=1G ~/Footage/
1839008 2021-07-14 13:55        /home/tux/Footage/snowfall.mp4
1577980 2020-04-11 13:10        /home/tux/Footage/waterfall.mp4
8588936 2021-07-14 13:55        /home/tux/Footage/

When file sizes get particularly large, they can be difficult to read. Make file sizes easier with the --human-readable (or -h for short) option:

$ \du --separate-dirs --all --time \
--threshold=1G --human-readable ~/Footage/
1.8G 2021-07-14 13:55        /home/tux/Footage/snowfall.mp4
1.6G 2020-04-11 13:10        /home/tux/Footage/waterfall.mp4
8.5G 2021-07-14 13:55        /home/tux/Footage/

See available disk space

To just get a summary of how much disk space remains on a drive, read our article about the df command.

What to read next
Seth Kenlon
Seth Kenlon is a UNIX geek, free culture advocate, independent multimedia artist, and D&D nerd. He has worked in the film and computing industry, often at the same time.

Comments are closed.

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.