How to Check your Disk Usage on Ubuntu from the command line Ubuntu Linux, like all unix varieties, includes the du command line utility. du stands for Disk Usage, as I’m sure you assumed.
How much space do I have free on my Linux drive?
Managing disk space on a Linux server is an important task. For example, package manager applications notify you how much disk space will be required for an installation. For that information to be meaningful, you should know how much space your system has available.
Prerequisites
- A Linux-based system
- A terminal window / command line
- A user account with sudo or root privileges
-
The
df
command stands for disk free, and it shows you the amount of space taken up by different drives. By default,df
displays values in 1-kilobyte blocks.Display Usage in Megabytes and Gigabytes
You can display disk usage in a more human-readable format by adding the–h
option:df –h
This displays the size in kilobytes (K), megabytes (M), and gigabytes (G).
Check Linux Disk Space Using df Command
In this tutorial, learn how to use the df
command to check disk space in Linux and the du
command to display file system disk space usage.
Go ahead, just type the command in your home directory:
nyongesa@ubuntu-desktop:~$ du
8 ./.gconf/desktop/gnome/accessibility/keyboard
12 ./.gconf/desktop/gnome/accessibility
8 ./.gconf/desktop/gnome/screen/default/0
12 ./.gconf/desktop/gnome/screen/default
16 ./.gconf/desktop/gnome/screen
8 ./.gconf/desktop/gnome/font_rendering
40 ./.gconf/desktop/gnome
44 ./.gconf/desktop
8 ./.gconf/apps/panel/applets/clock_screen0/prefs
16 ./.gconf/apps/panel/applets/clock_screen0
8 ./.gconf/apps/panel/applets/trashapplet_screen0
8 ./.gconf/apps/panel/applets/workspace_switcher_screen0/prefs
16 ./.gconf/apps/panel/applets/workspace_switcher_screen0
It shows you a very verbose output by default, which isn’t always extremely useful. Thankfully it also includes a lot of extra options.
To find the total size of files and folders in our current directory, listed by MB:
nyongesa@ubuntu-desktop:~$ du -s -m *
1 Desktop
0 Examples
17 VMwareTools-5.5.2-29772.tar.gz
Understanding the Output Format
The df
command lists several columns:
Filesystem Size Used Avail Use% Mounted on
udev 210M 0 210M 0% /dev
tmpfs 49M 1004K 48M 3% /run
/dev/sda2 7.9G 4.3G 3.2G 58% /
Your output may have more entries. The columns should be self-explanatory:
- Filesystem – This is the name of each particular drive. This includes physical hard drives, logical (partitioned) drives, and virtual or temporary drives.
- Size – The size of the filesystem.
- Used – Amount of space used on each filesystem.
- Avail – The amount of unused (free) space on the filesystem.
- Use% – Shows the percent of the disk used.
- Mounted on – This is the directory where the file system is located. This is also sometimes called a mount point.
The list of filesystems includes your physical hard drive, as well as virtual hard drives:
- /dev/sda2 – This is your physical hard drive. It may be listed as /sda1, /sda0, or you may even have more than one. /dev stands for device.
- udev – This is a virtual directory for the /dev directory. This is part of the Linux operating system.
- tmpfs – You may have several of these. These are used by /run and other Linux processes as temporary filesystems for running the operating system. For example, the tmpfs /run/lock is used to create lockfiles. These are the files that prevent multiple users from changing the same file at the same time.
Display a Specific File System
The df
command can be used to display a specific file system:
df –h /dev/sda2
You can also use a backslash:
df –h /
This displays the usage on your primary hard drive. Use the mount point (in the Mounted on column) to specify the drive you want to check.
Note: The df
command only targets a full filesystem. Even if you specify an individual directory, df
will read the space of the whole drive.
Now we are getting somewhere. That’s some pretty useful output.