Getting to grips with Linux can be tough for newcomers. But the power of command line tools should not be overlooked. They may look old fashioned—requiring zero mouse use—but tricks like the df command can save you time.
With the Linux df command you can easily interrogate your system for details on disk space and file size. These 12 df command examples will show you how.
What Is the df Command in Linux?
If you want to know how much disk space is free on your Linux PC, what is your first instinct? For many it might be to check your Linux distro’s disk management tool, but this isn’t the best option. Just as there is a data duplicator tool for cloning disks, there is also a “disk filesystem” tool for checking details about the filesystem.
This is the
df command, entered in the bash terminal. It can be used in so many ways:
- Display disk space usage
- Display usage on a specific device
- Show all file systems in use
- Find disk information on a specific file
- Display inodes
- Show the file system on a specific file
- Include file system types
- Exclude file system types
- Display the df command help file
- Show grand total disk usage and free space
df command can also be tweaked to display file sizes and free space in kilobytes, megabytes, and gigabytes.
The df Command Syntax
Before you start using the
df command, be aware of its syntax. Like most Linux terminal tools, it is straightforward; knowing it will save time as you use
df more often.
You can check the
df command syntax manually with the help command:
You’ll see the first line:
Usage: df [OPTION]... [FILE]...
So, you would use
df followed by the
[OPTION] then any relevant
[FILE] or directory. These are listed in the help file, but you can keep reading to see some examples demonstrated.
1. Display Disk Usage With the df Command
To display your computer’s disk space, which results in file system type, used and available space, and more, use:
2. Display Disk Usage for a Specific Drive With df
You can get more specific by selecting a specific drive or partition. Simply add the file path as the
3. Display All File Systems With df
df command only shows standard file systems on your computer. Inaccessible file systems, duplicates (in a RAID system for example) and pseudo file systems are ignored.
However, you can display these using
df. Just use the
-a switch, for “all”:
4. Find Information for a Specific File
Looking for data concerning a specific file? If you need to know where a particular file is and the remaining space on the device it is stored on, use:
This is useful when tracking down data to move between hard disk drives. For example, you might be migrating important personal data to a secondary drive or partition.
5. Display Inodes With df
Inodes are key to Linux file systems, storing information about files much like a database. To show information about inodes input
6. Use the df Command to Display File System
Need to know what file system type is in use on your drives? Use the
-T option, followed by a file path.
df -T /home/christian/file.txt
Look for the Type column heading. As you can see in this example, the filetype is ext4.
7. Include and Exclude File System Types with df
As well as displaying file system types with
df, you can also include specific types. For example, if you wanted to display all ext4 file system devices use:
df -t ext4
8. Exclude File System Types
Want to exclude a file system type? To display all file system types on your drive except ext4, use:
df -x ext4
9. View Grand Total Disk Usage With the df Command
While the basic
df displays a summarized total of disk usage, it doesn’t include hidden files. To see this figure instead, use
10. Check the df Command Help File
df commands can be found in this list, you’ll find some additional, rarely used examples in the help file. View this with
Bonus: Display df Results in KB, MB, and GB
In addition to all of that, the df command can be tweaked slightly to deliver more readable results. By default, the output is in bytes. If you know how bytes relate to megabytes and gigabytes, this may not be an issue for you.
However, for readability it is a smart option to use these switches:
- Make the standard output readable to humans familiar with GB numbering with
dfcommand output in megabytes (MB) with
- You can also display output in kilobytes with
Usage is straightforward—the option appears in the specified position, alongside any others that are selected if necessary. For the basic
df command, use
If you want to see the size of a specific file in GB rather than the default bytes, use the file path and filename:
df -h /home/christian/file.txt
The df Command Is Key to Successful Linux Use
By now you should have gained some familiarity with the
df command. Yes, you can live without it and perhaps find the info you need in the file manager. But with as little as two keystrokes you can also find the information in the terminal.
As typing is almost always faster than using a mouse, it makes sense to have this command line trick ready.
Want more Linux terminal commands like
df? Become a Linux command line master with these tips and tricks.
Read the full article: 13 df Linux Commands With Examples
Credits Make Use Of
I post weekly videos to my YouTube Channel, and the videos could be anything from the latest Tech News, Smartphone News, Gadget Reviews, Streaming Tips, VPN reviews and much more!