The Wayback Machine - https://web.archive.org/web/20240721145136/https://www.geeksforgeeks.org/df-command-in-linux-with-examples/
Open In App

df Command in Linux with examples

Last Updated : 22 Oct, 2021
Improve
Suggest changes
Post a comment
Like Article
Like
Save
Share
Report

There might come a situation while using Linux when you want to know the amount of space consumed by a particular file system on your LINUX system or how much space is available on a particular file system. LINUX being command friendly provides a command line utility for this i.e df command that displays the amount of disk space available on the file system containing each file name argument.

  • If no file name is passed as an argument with df command then it shows the space available on all currently mounted file systems
  • . This is something you might wanna know cause df command is not able to show the space available on unmounted file systems and the reason for this is that for doing this on some systems requires very deep knowledge of file system structures.
  • By default, df shows the disk space in 1 K blocks.
  • df displays the values in the units of first available SIZE from –block-size (which is an option) and from the DF_BLOCK_SIZE, BLOCKSIZE AND BLOCK_SIZE environment variables.
  • By default, units are set to 1024 bytes or 512 bytes(if POSIXLY_CORRECT is set) . Here, SIZE is an integer and optional unit and units are K, M, G, T, P, E, Z, Y (as K in kilo) .

df Syntax : 

df [OPTION]...[FILE]...
OPTION : to the options compatible with df command 
FILE : specific filename in case you want to know 
the disk space usage of a particular file system only. 

Using df command

Suppose you have a file named kt.txt and you want to know the used disk space on the file system that contains this file then you can use df in this case as: 

// using df for a specific file //

$df kt.txt
Filesystem     1K-blocks      Used Available Use% Mounted on 
/dev/the2        1957124      1512   1955612   1% /snap/core 

/* the df only showed the disk usage 
details of the file system that
contains file kt.txt */

Now, what if you don’t give any filename t df, in that case df displays the disk usage information for all mounted file systems as shown below: 

//using df without any filename //

$df
Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/loop0      18761008  15246876   2554440  86% /
none                   4         0         4   0% /sys/fs/cgroup
udev              493812         4    493808   1% /dev
tmpfs             100672      1364     99308   2% /run
none                5120         0      5120   0% /run/lock
none              503352      1764    501588   1% /run/shm
none              102400        20    102380   1% /run/user
/dev/the2        1957124      1512   1955612   1% /snap/core 

/* in this case df displayed 
the disk usage details of all
mounted file systems */

Options for df command

  • -a,- -all : It includes all the dummy files also in the output which are actually having zero block sizes.
  • -B,- -block-size=S : This is the option we were talking in the above para which is used to scale sizes by SIZE like -BM prints sizes in units of 1,048,576 bytes.
  • – -total : It is used to display the grand total for size.
  • -h,- -human-readable : It print sizes in human readable format.
  • -H,- -si : This option is same as -h but it use powers of 1000 instead of 1024.
  • -i,- -inodes : This option is used when you want to display the inode information instead of block usage.
  • -k : Its use is like –block-size-1k.
  • -l,- -local : This will display the disk usage of only local file systems.
  • -P,- -portability : It uses the POSIX output format.
  • -t,- -type=TYPE : It will only show the output of file systems having type TYPE.
  • -T,- -print-type : This option is used to print file system type shown in the output.
  • -x,- -exclude-type=TYPE : It will exclude all the file systems having type TYPE from the output.
  • -v : Ignored, included for compatibility reasons.
  • – -no-sync : This is the default setting i.e not to invoke sync before getting usage info.
  • – -sync : It invokes a sync before getting usage info.
  • – -help : It displays a help message and exit.
  • – -version : It displays version information and exit.

Examples of using df with options

1. Using -a : If there is a need to display all file systems along with those which has zero block sizes then use -a option with df. 

//using df with -a//

$df -a
Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/loop0      18761008  15246876   2554440  86% /
none                   4         0         4   0% /sys/fs/cgroup
udev              493812         4    493808   1% /dev
tmpfs             100672      1364     99308   2% /run
none                5120         0      5120   0% /run/lock
none              503352      1764    501588   1% /run/shm
none              102400        20    102380   1% /run/user
/dev/sda3      174766076 164417964  10348112  95% /host
systemd                0         0         0    - /sys/fs/cgroup

/* in this case
systemd file system 
having zero block 
size is also displayed */

2. Using -h : This is used to make df command display the output in human-readable format. 

//using -h with df//

$df -h kt.txt
Filesystem     1K-blocks      Used Available Use% Mounted on 
/dev/the2           1.9G      1.5M      1.9G   1% /snap/core 

/*this output is 
easily understandable by 
the user and all
cause of -h option */

In the above, G and M represents Gigabytes and Megabytes respectively. You can use -h with df only to produce the output in readable format for all the mounted file systems rather than just of the file system containing kt.txt file. 

3. Using -k : This displays the file system information and usage in 1 K blocks. 

//using -k with df//

$df -k kt.txt
Filesystem     1K-blocks      Used Available Use% Mounted on 
/dev/the2        1957124      1512   1955612   1% /snap/core 

/* no change cause the
output was initially
shown in the usage
of 1K bytes only */

4. Using – -total : This option is used to produce total for a size, used and available columns in the output. 

//using --total with df//

$df --total 
Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/loop0      18761008  15246876   2554440  86% /
none                   4         0         4   0% /sys/fs/cgroup
udev              493812         4    493808   1% /dev
tmpfs             100672      1364     99308   2% /run
none                5120         0      5120   0% /run/lock
none              503352      1764    501588   1% /run/shm
none              102400        20    102380   1% /run/user
/dev/the2        1957124      1512   1955612   1% /snap/core 
total           21923492  15251540   5712260  92% -                       

/* the total row 
is added in the 
output */

5. Using -T : With the help of this option, you will be able to see the corresponding type of the file system as shown. 

/using -T with df//

$df -T kt.txt
Filesystem     Type     1K-blocks      Used Available Use% Mounted on 
/dev/the2      squashfs   1957124      1512   1955612   1% /snap/core 

/* you can use
-T with df only
to display type of
all the mounted
file systems */

6. Using -t : This is used when you wish the disk usage information of the file systems having a particular type only. 

//using -t with df//

$df -t squashfs
Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/loop0      18761008  15246876   2554440  86% /
/dev/the2        1957124      1512   1955612   1% /snap/core 


/*so the df 
displayed only the 
info of the file
systems having type
squashfs */

7. Using -x : Now, you can also tell df to display the disk usage info of all the file systems except those having a particular type with the help of -x option. 

//using -x with df//

$df -x squashfs
Filesystem     1K-blocks      Used Available Use% Mounted on
none                   4         0         4   0% /sys/fs/cgroup
udev              493812         4    493808   1% /dev
tmpfs             100672      1364     99308   2% /run
none                5120         0      5120   0% /run/lock
none              503352      1764    501588   1% /run/shm
none              102400        20    102380   1% /run/user

/* in this case info of
/dev/the2 and /dev/loop0
file systems aren't
displayed cause they are 
of type squashfs */

8. Using -i : This option is used to display inode information in the output. 

//using -i with df//

$df -i kt.txt
Filesystem     Inodes  IUsed    IFree Iuse% Mounted on 
/dev/the2      489281     48   489233    1% /snap/core

/*showing inode info
of file system
having file kt.txt */

When -i option is used then the second, third, and fourth columns displays inode-related figures instead of disk related. 

9. Using – -sync : By default, the df command produces output with – -no-sync option which will not perform the sync system call prior to reporting usage information. Now we can use – -sync option which will force a sync resulting in the output being fully up to date. 

//using --sync option//

$df --sync
Filesystem     1K-blocks      Used Available Use% Mounted on
/dev/loop0      18761008  15246876   2554440  86% /
none                   4         0         4   0% /sys/fs/cgroup
udev              493812         4    493808   1% /dev
tmpfs             100672      1364     99308   2% /run
none                5120         0      5120   0% /run/lock
none              503352      1764    501588   1% /run/shm
none              102400        20    102380   1% /run/user
/dev/the2        1957124      1512   1955612   1% /snap/core 

/* in this case 
no change in the output
is observed cause it is 
possible that there is no
update info present to
be reflected */

10. Using -l : When we run df command then by default it shows any externally mounted file systems which include those from external NFS or Samba servers. We can hide the info of these external file systems from output with -l option syntax of which is shown below.  

$df -l

So, this is all about df command. 



Previous Article
Next Article

Similar Reads

Ccat – Colorize Cat Command Output command in Linux with Examples
ccat is a command-line tool for Linux and OSX, which is similar to the cat command in Linux. But the difference between cat and ccat is that the ccat shows the content of the file with the syntax highlighted. Currently, ccat supports the following programming languages. JavaScriptJavaRubyPythonGoCJSONInstallation of Ccat First, we are going to see
2 min read
How to Display Command History in Linux | history Command
The command-line interface in Linux provides powerful tools for users, and mastering command history is essential for efficient navigation and retrieval of previously executed commands. The history command is a valuable utility that allows users to view and search through their command history. In this comprehensive guide, we will explore the vario
4 min read
select command in Linux with examples
select command in Linux is used to create a numbered menu from which a user can select an option. If the user enters a valid option then it executes the set of command written in select block and then ask again to enter a number, if a wrong option is entered it does nothing. If user enters nothing and simply press 'enter' the option menu gets print
1 min read
atrm command in Linux with examples
atrm command is used to remove the specified jobs. To remove a job, its job number is passed in the command. A user can only delete jobs that belong to him. Only superuser can delete any job even if that belongs to another user. Syntax: atrm [-V] job [job...] Options: -V : Used to print the version number atrm -V job : Job number of the job which i
1 min read
comm command in Linux with examples
comm compare two sorted files line by line and write to standard output; the lines that are common and the lines that are unique. Suppose you have two lists of people and you are asked to find out the names available in one and not in the other, or even those common to both. comm is the command that will help you to achieve this. It requires two so
5 min read
cmp Command in Linux with examples
cmp command in Linux/UNIX is used to compare the two files byte by byte and helps you to find out whether the two files are identical or not. When cmp is used for comparison between two files, it reports the location of the first mismatch to the screen if difference is found and if no difference is found i.e the files compared are identical.cmp dis
5 min read
expand Command in LINUX with examples
Whenever you work with files in LINUX there can be a situation when you are stuck with a file containing many tabs and whatever you need to do with a file requires that file with no tabs but with spaces. In this situation, the task looks quite simple if you are dealing with a small file but what if the file you are dealing with is very big or you n
3 min read
help Command in Linux with examples
If you are new to LINUX operating system and having trouble dealing with the command-line utilities provided by LINUX then you really need to know first of all about the help command which as its name says help you to learn about any built-in command. help command as told before just displays information about shell built-in commands. Here's the sy
3 min read
fgrep command in Linux with examples
The fgrep filter is used to search for the fixed-character strings in a file. There can be multiple files also to be searched. This command is useful when you need to search for strings which contain lots of regular expression metacharacters, such as "^", "$", etc. Syntax: fgrep [options] [ -e pattern_list] [pattern] [file] Options with Description
3 min read
rcp Command in Linux with examples
There comes a time while using LINUX when there is a need to copy some information stored in a file to another computer. This can be done simply using rcp command line utility . Obviously there exists some other methods to complete the above mentioned task which are more secure (like scp or rsync) but this command lets you do this in the simple way
4 min read
three90RightbarBannerImg