frame

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Register

[How Do I Find Out?] How Much Disk Space I Have Left?

LawrenceLawrence Member
edited February 2020 in Performance and Security
Introduction

In this tutorial, we will learn how to find out what is using the server's space and in what folders it's located. We will be using df and du commands. With these two commands, not only can you discover details about the free space on the mounted file systems, but you can also see the amount of space used by individual directories.

For this tutorial we are using Ubuntu 16.04 distribution, however, you should be able to use it for all distributions we offer on Time4VPS.

Update System

First things first. Like always, first of all, we recommend updating your server. It can be done by simply executing:

apt-get update

yum update




df (abbreviation for disk free) is a standard Unix command used to display the amount of available disk space for file systems on which the invoking user has appropriate read access. The df command shows the disk space usage on all the currently mounted file systems. Here is what the output from running the df command without any parameters might look like. If a file system name is used as an argument (e.g. /dev/sda1) only the information for that file system will be displayed:

df



The first column “Filesystem” gives the name of the storage (e.g. /dev/simfs) while the second column shows the size of the filesystem in Kilobytes. Likewise, the third and fourth columns show how much of the filesystem is used and how much is free while the penultimate column shows the usage as a percentage. The last column “Mounted on” shows the path where the filesystem was mounted. Having the size of the volume, the amount used and the free space listed in Kilobytes can make the output from df hard to read. Fortunately, the “-h” option changes the output into something more friendly:

df -h



Another couple of useful flags for df are “-T” which will add an extra column to the output listing the type of each filesystem, and “-l” which will force df to only show the local filesystems (meaning that remote filesystems mounted via NFS won’t be displayed).




While df is an easy way of getting an overview, du (abbreviation for disk usage) gives a better picture of what is taking up space on your system. du displays how much disk space a directory is occupying:

du

Same as for df, for a more friendly output use the “-h” option:

du -h

To find out the total amount of disk space used without seeing the details of the various subdirectories, use the “-s” parameter. Used together with “-h“, the command looks like this:

du -hs

If you tried one of above du commands you probably saw that output is really huge, it shows all folders, their sub-folder, sub-folders of that sub-folders... I think you got the idea. But there is really nice command that shows used space only of folders and does not go deeper:

du --max-depth=1 | sort -n | awk 'BEGIN {OFMT = "%.0f"} {print $1/1024,"MB", $2}'



Conclusion

The df and du commands can be very useful for monitoring disk usage and for finding directories and/or files that are occupying large amounts of space.

There are many other options that can change the output. Explore the help and man page for more ideas.
Sign In or Register to comment.

Time4VPS

Learn how to install a web and database server, email, FTP client or other applications. Discover and share information on server security or optimization recommendations.
Feel free to join our constantly expanding community, participate in discussions, strengthen your knowledge on Linux and Windows server management!
© 2013 - 2024 Time4VPS. All rights reserved.

Get In Touch