FactorPad
Faster Learning Tutorials

Linux df command summary with examples

df allows you to display file or file system space.
  1. Purpose - Learn what df is for and how to find help.
  2. Options - Review a few common options and examples.
  3. Examples - Walk through code examples with df.
  4. A tip - Finish off with one more insight.
Paul Alan Davis, CFA, October 28, 2016
Updated: August 2, 2018
In this tutorial, 51 of 100, below find a 3-4 minute introductory video, a text-based tutorial and all of the code examples from the video.

Outline Back Next

~/ home  / tech  / linux essentials  / df command


The Linux df command

Beginner

Video Tutorial

Linux df command summary with examples (3:44)

Videos can also be accessed from the YouTube Playlist.

Video Script

The Command and Why You Need It

Our fifty-first word, or command to memorize is df from our category System.

df allows you to display file or file system space.

Recall from the last video on stat, we looked at permissions, timestamps and file system size, well here we'll focus on size and usage statistics.

Before we start, it helps to think of commands as mini programs and most follow this structure: command -option(s) argument(s).

The df command has 18 options and the argument is the file or file system name.

Like most commands, help is available with double-dash --help, -h reports in human-readable form, like 1k for 1 kilobyte, 1M for one megabyte, 1G for 1 gigabyte.

And to report specific items, we can use --output=FIELDS.

So why is df an important command? Well, space is a limited resource and nobody likes to run out, so we periodically need to check in on our allocation. And now you know how to do that.

Demonstration

Okay, the best way to embed this in your memory is by typing in your own terminal window.

Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows.

Here we go. So to illustrate the difference between entering files or file systems, let's do a quick df on the file system located in devices at /dev/sdb1.

$ df /dev/sdb1 Filesystem 1K-blocks Used Available Use% Mounted on /dev/sdb1 5028480 10632 4739372 1% /home

Or refer to it as our home directory using /home.

$ df /home Filesystem 1K-blocks Used Available Use% Mounted on /dev/sdb1 5028480 10632 4739372 1% /home

Same thing, right? But now let's work on this because this isn't user-friendly.

Now we'll make it more friendly, using the -h option.

$ df -h /home Filesystem Size Used Avail Use% Mounted on /dev/sdb1 4.8G 11M 4.6G 1% /home

We all understand this 1%, but most of us think in terms of gigabytes and megabytes. Beyond that, we don't care to get more granular.

And last, let's tack on the --output option with ='size','pcent' coded up like this for the /home directory.

$ df -h --output='size','pcent' /home Size Use% 4.8G 1%

And voilà. The information we really care about.

A Final Tip

Okay now you know how to use df. And you know the syntax for commands, options and arguments.

One last tip about the df command. So I suggest starting to think of a use case, like using df to kick off an email to users who are nearing their capacity.

Okay, thanks for visiting today. I hope this was a helpful introduction to the df command.


Learn More About The Series

For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:


What's Next?

If you learned something today, please consider subscribing to the YouTube Channel.

  • For the Outline to all 100 tutorials, click Outline.
  • To go back to the stat command, hit Back.
  • To learn another disk space command with du, click Next.

Outline Back Next

~/ home  / tech  / linux essentials  / df command



 
 
Keywords:
linux df command
df linux
unix df
linux df examples
man df
disk usage linux
df linux command
linux free disk space
linux free space
linux file system space
linux command disk space
print disk free space
linux free disk space
linux df tutorial