11 df commands in Linux (with example)
With the df command in Linux, you can easily check your system for details about disk space and file size. These 12 examples of df commands will show you how to do them in detail.
Getting acquainted with Linux can be difficult for beginners. But not so that you ignore the power of command line tools. They look outdated (because they don't use a mouse). but tricks like the df command can save you time.
With the df command in Linux, you can easily check your system for details about disk space and file size. These 12 examples of df commands will show you how to do them in detail.
How to use the df command in Linux
- What is the df command in Linux?
- Syntax of df command
- 1. Display disk usage with df command
- 2. Display the disk usage for a specific drive with df
- 3. Show all file systems with df
- 4. Find information for a specific file
- 5. Display the inode with df
- 6. Use the df command to display the file system
- 7. Includes file system types with df
- 8. Exclude file system types
- 9. View the total disk space usage with the df command
- 10. Check the Help File of the df command
- 11. Display df results in KB, MB and GB
- The df command is the key to successful Linux use
What is the df command in Linux?
If you want to know how much free disk space is available on a Linux PC, what is the first thing you do? Many people can check the disk management tool of the Linux distribution they are using, but this is not the best option.
This is the df command, entered in terminal bash. It can be used in many ways:
- Show disk space usage
- Show usage on a specific device
- Show all file systems in use
- Find drive information on a specific file
- Show the inode
- Display the file system on a specific file
- Including file system types
- Exclude file system types
- Display the Help File (explanation) for the df command
- Displays total disk usage and free space
- The df command can also be adjusted to display file size and free space in kilobytes, megabytes, and gigabytes.
Syntax of df command
Before you start using the df command, note its syntax. Like most Linux terminal tools, this command is very simple. If you use df regularly, you will save a lot of time.
You can check the syntax of the df command manually with the help command:
df --help
You should see the first line:
Usage: df [OPTION]. [FILE].
So you would use df followed by [OPTION], then any [FILE] or related directories. They are listed in the Help File section, but you can continue reading to see some examples presented.
1. Display disk usage with df command
To display computer drive space, along with the type of file system, used and available space, etc., use:
df
2. Display the disk usage for a specific drive with df
You can get more specific information by selecting a specific drive or partition. Just add the file path as [OPTION]:
df /home
3. Show all file systems with df
The default df command only displays the standard file systems on the computer. Inaccessible file systems, duplicates (in RAID systems, for example) and many pseudo file systems are ignored.
However, you can display them by using df. Just use the -a switch , short for 'all' :
df -a
4. Find information for a specific file
You need to search data related to a specific file? If you need to know where a specific file is and the remaining space on the device it's stored on, use:
df /home/christian/file.txt
This command is useful when monitoring data to move between hard drives. For example, you can move important personal data to a secondary drive or partition.
5. Display the inode with df
Inode is a key element for Linux file systems, which stores information about files like databases. To display information about inode input, use the following command:
df -i
6. Use the df command to display the file system
If you need to know what kind of file system is used on the drives, use the -T option , followed by the file path.
df -T /home/christian/file.txt
Find the column heading Type. As you can see in this example, the filetype is ext4.
7. Includes file system types with df
As well as displaying file system types with df, you can also include specific types. For example, if you want to display all of the ext4 file systems that your device uses, use the following command:
df -t ext4
8. Exclude file system types
Do you want to exclude a file system type? To display all types of file systems on the drive, except for ext4, use:
df -x ext4
9. View the total disk space usage with the df command
Although the df command basically shows the total disk usage, it does not include hidden files. To see this number, use
df --total
10. Check the Help File of the df command
Although most df commands can be found in this list, you will find some additional examples, rarely used in the Help File section. See these examples with:
df --help
11. Display df results in KB, MB and GB
In addition to all of the above, the df command may be slightly modified to provide a more readable result. By default, the output is calculated in bytes. If you know the relationship between bytes, megabytes and gigabytes, this may not be a problem.
However, for ease of reading, it's best to use these switches:
- Make the standard output more familiar and readable with the GB numbering with -h
- Display df command output in megabytes (MB) with -m
- You can also display the output in kilobytes with -k
The usage is very simple, the option appears in the specified position, next to any other options selected, if needed. For basic df command, use
df -h
If you want to see the size of a specific file in GB instead of the default byte, use the path and file name:
df -h /home/christian/file.txt
The df command is the key to successful Linux use
Now you are familiar with the df command. Yes, you might be able to find the information you need in the file manager. But with only 2 key presses, you can also find information right in the terminal.
Because typing is almost always faster than using a mouse, using the built-in command line trick like this is always helpful.
If you want to learn about many other Linux terminal commands such as df, check out these articles: 10 useful tips to help you 'master' the Linux commands simpler and the 10 most useful Linux commands for more details .
You should read it
- How to use the which command in Linux
- 20+ essential Linux security commands
- How to use the stat command on Linux
- The Cat command in Linux
- Basic Linux commands everyone needs to know
- 14 interesting Linux commands in Terminal
- 11 uses of ps command in Linux
- How to use ss command on Linux
- How to use the last command in Linux
- The dd command in Linux, How to use the dd command
- How to use the history command in Linux
- Instructions for using find command in Linux