11 df commands in Linux (with example)
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
May be interested
- How to run 2 or more Terminal commands at the same time on Linuxif you use linux, you probably know how to use useful commands to work with files, install software and launch programs. however, one thing you don't know is that you can still run multiple commands at the same time.
- Basic Linux commands everyone needs to know - Operations on Linux are much fasterwhen using linux, you should also learn basic linux commands to perform operations more quickly and easily. below are some basic linux commands you should know.
- 10 most useful Linux commandsfor those who are new to linux, administration will face many difficulties. here are the 10 most useful linux commands that make your administration a lot easier.
- How to run Linux commands when starting Windows Subsystem for Linux on Windows 10the latest beta version of windows 10 allows users to automatically run linux commands when windows subsystem for linux starts.
- How to schedule Linux commands with 'at'utility at very easy to use. users only need to give time and date as command line parameters, then enter one or more commands to execute.
- Linux Error SUDO allows you to run commands as roota flaw in the sudo linux command has been discovered, which may allow non-privileged users to execute commands as root.
- 20+ essential Linux security commandshere are some of the most important security commands for everyday work on linux systems. if you're interested in security issues on your linux system, don't ignore these helpful security commands.
- 7 commands to manipulate the most basic files and folders everyone must knowon windows or linux operating systems, there are a number of things that users can only do with commands. in the following article, the network administrator will introduce you to the 7 most basic commands that any user must 'understand' to perform operations faster.
- Basic utilities: print, email in Unixby this chapter, you have a few basic insights about unix systems and some of its basic commands. this chapter will briefly discuss some of the basic but important utilities of unix utilities that you will use in your daily activities.
- Extremely dangerous commands on Windows, Linux, Mac, don't try even oncethere are commands that are used to provide certain features to the operating system. however, if used improperly, they cause danger and damage the operating system.