Linux Commands – df
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
In the last blog post, we have discussed du command in Linux which is used to get disk space utilization of files and directories.
https://cloudaffaire.com/linux-commands-du/
In this blog post, we will discuss df command in Linux. df command is used to get file system disk space usage. df command without any argument prints the current disk space usage of file systems. You can also specify a file system as an argument to get a specific file system disk space usage. df command can be used to print the below information about the file system.
- source: The source of the mount point, usually a device.
- fstype: File system type.
- itotal: Total number of inodes.
- iused: Number of used inodes.
- iavail: Number of available inodes.
- ipcent: Percentage of IUSED divided by ITOTAL.
- size: Total number of blocks.
- used: Number of used blocks.
- avail: Number of available blocks.
- pcent: Percentage of USED divided by SIZE.
- file: The file name if specified on the command line.
- target: The mount point.
Linux Commands – df:
df command without any arguments prints the current file systems disk space usage. By default, the disk space is printed in units of 1024 bytes, but this can be overridden block size option and source, size, used, avail, pcent, target columns are returned. You can also get a specific file system disk space usage by passing it as an argument to df command.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
######################### ## Linux Commands | df ## ######################### ## Prerequisites: One Unix/Linux/POSIX-compliant operating system with bash shell ##--- ## df ##--- ## df [option]... [FILE]... ## df command df ## returns all file systems disk space usage ## returns ## Filesystem 1K-blocks Used Available Use% Mounted on ## devtmpfs 485468 0 485468 0% /dev ## tmpfs 503480 0 503480 0% /dev/shm ## tmpfs 503480 472 503008 1% /run ## tmpfs 503480 0 503480 0% /sys/fs/cgroup ## /dev/xvda1 8376300 1740376 6635924 21% / ## tmpfs 100696 0 100696 0% /run/user/1000 df --o ## returns all columns available in df output df / ## returns root file system disk space usage ## /dev/xvda1 8376300 1740336 6635964 21% / |
You can use df -a or –all options to print all file systems (including dummy, duplicate, or inaccessible file systems which are omitted by default). Dummy file systems are typically special purpose pseudo file systems such as ‘/proc’, with no associated storage. Duplicate file systems are local or remote file systems that are mounted at separate locations in the local file hierarchy, or bind mounted locations. Inaccessible file systems are those which are mounted but subsequently over-mounted by another file system at that point, or otherwise inaccessible due to permissions of the mount point, etc.
1 2 3 |
## df -a or --all options df -a |
You can use df -h or –human-readable or -H options to print the size in a human-readable format. In a human-readable format, a size letter to each size, such as ‘M’ for mebibytes is appended to the size. Powers of 1024 are used, not 1000; ‘M’ stands for 1,048,576 bytes. This option is equivalent to ‘–block-size=human-readable’. Use the ‘–si’ option or -H option if you prefer powers of 1000.
1 2 3 4 5 6 7 |
## df -h or --human-readable or -H options df -h ## returns the size in KB, MB, GB etc. df -H ## returns size in units of 1000 instead of 1024 df --si ## returns size in units of 1000 instead of 1024 |
You can use df -B SIZE or –block-size=SIZE options to scale sizes by SIZE before printing them. You can define SIZE in integers (1,1024 etc. or 1,1000 etc. unit in bytes) or in characters (K, M, G, T, P, E, Z, Y, si). You can also use du -k or -m options to display the size in KB or MB. You can also used predefined block size using -k for KB and -m for MB.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
## df -B SIZE or --block-size=SIZE options df ## returns size in 1024 bytes (KB default) df -B1 ## returns size in bytes df -BK ## returns size in kilo bytes (KB) df -BM ## returns size in mega bytes (MB) df -BG ## returns size in giga bytes (GB) df -k ## returns size in kilo bytes (KB) df -m ## returns size in mega bytes (MB) |
You can use df –total options to print a grand total of all arguments after all arguments have been processed. This can be used to find out the total disk size, usage, and available space of all listed devices.
1 2 3 4 5 6 |
## df --total options df -h --total ## returns total usage at the end ## Filesystem Size Used Avail Use% Mounted on ## total 10G 1.7G 8.4G 17% - |
You can use df -i or –inodes options to list inode usage information instead of block usage. An inode (short for index node) contains information about a file such as its owner, permissions, timestamps, and location on the disk.
1 2 3 |
## df -i or --inodes options df -i ## returns itotal,iused,iavail,ipcent columns related to inodes |
You can use df –output or –output=FIELD_LIST options to output format defined by FIELD_LIST, or print all fields if FIELD_LIST is omitted. FIELD_LIST is a comma-separated list of columns to be included in df command output and therefore effectively controls the order of output columns. Each field can thus be used at the place of choice, but yet must only be used once.
1 2 3 4 5 6 |
## df --output or --output=FIELD_LIST options df --output ## returns all available column ## returns columns in FIELD_LIST df --output=source,fstype,itotal,iused,iavail,ipcent,target |
You can use df –direct option to not resolve mount point and show statistics directly for a file. It can be especially useful for NFS mount points if there is a boundary between two storage policies behind the mount point.
1 2 3 |
## df --direct option df --direct ## show statistics directly for a file |
You can use df -l or –local options to limit the listing to local file systems. By default, remote file systems are also listed.
1 2 3 |
## df -l or --local options df -l ## show statistics only local file system |
You can use df –sync option to invoke the sync system call before getting any usage data. On some systems (notably SunOS), doing this yields more up to date results, but in general this option makes ‘df’ much slower, especially when there are many or very busy file systems.
1 2 3 4 5 |
## df --sync option df --no-sync ## this is default of df df --sync ## sync before display |
You can use df -T or –print-type options to print file system type.
1 2 3 4 5 |
## df -T or --print-type options df ## does not display file system type by default df -T ## displays the file system type |
You can use df -t or –type=TYPE options to limit the listing to file systems of type TYPE.
1 2 3 |
## df -t or --type=TYPE options df -T --type=xfs ## display only xfs file system usage |
You can use df -x or –exclude-type=TYPE options to limit the listing to file systems, not of type TYPE.
1 2 3 |
## df -x or --exclude-type=TYPE options df -T --exclude-type=tmpfs ## exclude file systems with type tmpfs |
Hope you have enjoyed this article. In the next blog post, we will discuss free command in Linux.