Friday, November 7, 2014

df ( disk free ) command examples



Syntax

df [OPTION]... [FILE]...

Description

df displays the amount of disk space available on the file system containing each file name argument. If no file name is given, the space available on all currently mounted file systems is shown. Disk space is shown in 1K blocks by default, unless the environment variable POSIXLY_CORRECT is set, in which case 512-byte blocks are used.
If an argument is the absolute file name of a disk device node containing a mounted file system, df shows the space available on that file system rather than on the file system containing the device node (which is always the root file system). df cannot show the space available on unmounted file systems, because on most kinds of systems doing so requires very system-specific knowledge of file system structures.
Display Information of df Command.
Using ‘–help‘ switch will display a list of available option that are used with df command.
[root@linux~]# df --help

Options


-a, --all
include dummy file systems.
-B, --block-size=SIZE
scale sizes by SIZE before printing them. E.g., '-BM' prints sizes in units of 1,048,576 bytes. See "SIZE Format" below for more information.
--total
display a grand total.
-h, --human-readable
print sizes in human readable format (e.g., 1K 234M 2G)
-H, --si
same as -h, but use powers of 1000 instead of 1024.
-i, --inodes
list inode information instead of block usage.
-k
like --block-size=1K.
-l, --local
limit listing to local file systems
--no-sync
do not invoke a sync before getting usage info (This is the default).
-P, --portability
use the POSIX output format.
--sync
invoke a sync before getting usage info.
-t, --type=TYPE
limit listing to file systems of type TYPE.
-T, --print-type
print file system type.
-x, --exclude-type=TYPE
limit listing to file systems not of type TYPE.
-v
(ignored; included for compatibility reasons.)
--help
display a help message and exit.
--version
output version information and exit.
Examples

 Check File System Disk Space Usage

The “df” command displays the information of device name, total blocks, total disk space, used disk space, available disk space and mount points on a file system.
[root@linux~]# df

Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/cciss/c0d0p2     78361192  23185840  51130588  32% /
/dev/cciss/c0d0p5     24797380  22273432   1243972  95% /home
/dev/cciss/c0d0p3     29753588  25503792   2713984  91% /data
/dev/cciss/c0d0p1       295561     21531    258770   8% /boot
tmpfs                   257476         0    257476   0% /dev/shm

 Display Information of all File System Disk Space Usage

The same as above, but it also displays information of dummy file systems along with all the file system disk usage and their memory utilization.
[root@linux~]# df -a

Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/cciss/c0d0p2     78361192  23186116  51130312  32% /
proc                         0         0         0   -  /proc
sysfs                        0         0         0   -  /sys
devpts                       0         0         0   -  /dev/pts
/dev/cciss/c0d0p5     24797380  22273432   1243972  95% /home
/dev/cciss/c0d0p3     29753588  25503792   2713984  91% /data
/dev/cciss/c0d0p1       295561     21531    258770   8% /boot
tmpfs                   257476         0    257476   0% /dev/shm
none                         0         0         0   -  /proc/sys/fs/binfmt_misc
sunrpc                       0         0         0   -  /var/lib/nfs/rpc_pipefs

 Show Disk Space Usage in Human Readable Format

Have you noticed that above commands displays information in bytes, which is not readable yet all, because we are in a habit of reading the sizes in megabytes, gigabytes etc. as it makes very easy to understand and remember.
The df command provides an option to display sizes in Human Readable formats by using ‘-h’ (prints the results in human readable format (e.g., 1K 2M 3G)).

[root@linux~]# df -h

Filesystem            Size  Used Avail Use% Mounted on
/dev/cciss/c0d0p2      75G   23G   49G  32% /
/dev/cciss/c0d0p5      24G   22G  1.2G  95% /home
/dev/cciss/c0d0p3      29G   25G  2.6G  91% /data
/dev/cciss/c0d0p1     289M   22M  253M   8% /boot
tmpfs                 252M     0  252M   0% /dev/shm

 Display Information of /home File System

To see the information of only device /home file system in human readable format use the following command.
[root@linux~]# df -hT /home

Filesystem                          Type    Size  Used Avail Use% Mounted on
/dev/cciss/c0d0p5           ext3     24G   22G  1.2G  95% /home

 Display Information of File System in Bytes

To display all file system information and usage in 1024-byte blocks, use the option ‘-k‘ (e.g. –block-size=1K) as follows.
[root@linux~]# df -k

Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/cciss/c0d0p2     78361192  23187212  51129216  32% /
/dev/cciss/c0d0p5     24797380  22273432   1243972  95% /home
/dev/cciss/c0d0p3     29753588  25503792   2713984  91% /data
/dev/cciss/c0d0p1       295561     21531    258770   8% /boot
tmpfs                   257476         0    257476   0% /dev/shm

 Display Information of File System in MB
To display information of all file system usage in MB (Mega Byte) use the option as ‘-m‘.
[root@linux~]# df -m

Filesystem           1M-blocks      Used Available Use% Mounted on
/dev/cciss/c0d0p2        76525     22644     49931  32% /
/dev/cciss/c0d0p5        24217     21752      1215  95% /home
/dev/cciss/c0d0p3        29057     24907      2651  91% /data
/dev/cciss/c0d0p1          289        22       253   8% /boot
tmpfs                      252         0       252   0% /dev/shm

 Display Information of File System in GB
To display information of all file system statistics in GB (Gigabyte) use the option as ‘df -h‘.
[root@linux~]# df -h

Filesystem            Size  Used Avail Use% Mounted on
/dev/cciss/c0d0p2      75G   23G   49G  32% /
/dev/cciss/c0d0p5      24G   22G  1.2G  95% /home
/dev/cciss/c0d0p3      29G   25G  2.6G  91% /data
/dev/cciss/c0d0p1     289M   22M  253M   8% /boot
tmpfs                 252M     0  252M   0% /dev/shm

 Display File System Inodes
Using ‘-i‘ switch will display the information of number of used inodes and their percentage for the file system.
[root@linux~]# df -i

Filesystem            Inodes   IUsed   IFree IUse% Mounted on
/dev/cciss/c0d0p2    20230848  133143 20097705    1% /
/dev/cciss/c0d0p5    6403712  798613 5605099   13% /home
/dev/cciss/c0d0p3    7685440 1388241 6297199   19% /data
/dev/cciss/c0d0p1      76304      40   76264    1% /boot
tmpfs                  64369       1   64368    1% /dev/shm

 Display File System Type
If you notice all the above commands output, you will see there is no file system type mentioned in the results. To check the file system type of your system use the option ‘T‘. It will display file system type along with other information.
[root@linux~]# df -T

Filesystem                          Type   1K-blocks  Used      Available Use% Mounted on
/dev/cciss/c0d0p2           ext3    78361192  23188812  51127616  32%   /
/dev/cciss/c0d0p5           ext3    24797380  22273432  1243972   95%   /home
/dev/cciss/c0d0p3           ext3    29753588  25503792  2713984   91%   /data
/dev/cciss/c0d0p1           ext3    295561     21531    258770    8%    /boot
tmpfs                                   tmpfs   257476         0    257476    0%   /dev/shm

 Include Certain File System Type
If you want to display certain file system type use the ‘-t‘ option. For example, the following command will only display ext3 file system.
[root@linux~]# df -t ext3

Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/cciss/c0d0p2     78361192  23190072  51126356  32% /
/dev/cciss/c0d0p5     24797380  22273432   1243972  95% /home
/dev/cciss/c0d0p3     29753588  25503792   2713984  91% /data
/dev/cciss/c0d0p1       295561     21531    258770   8% /boot

 Exclude Certain File System Type
If you want to display file system type that doesn’t belongs to ext3 type use the option as ‘-x‘. For example, the following command will only display other file systems types other than ext3.
[root@linux~]# df -x ext3

Filesystem           1K-blocks      Used Available Use% Mounted on
tmpfs                   257476         0    257476   0% /dev/shm


List Inodes (Instead of Block Usage)

If information in terms of inode is desired then df provides an option ‘-i’ for this.
$ df -i
Filesystem            Inodes   IUsed   IFree IUse% Mounted on
/dev/sda1            8396800   65397 8331403    1% /
tmpfs                1005469       1 1005468    1% /dev/shm
/dev/sdb2            1966560    2517 1964043    1% /home/oracle
/dev/sdc1            36593664      11 36593653    1% /home/data
So we see that information in terms of inodes is displayed.

Display Grand Total in the Output

If we want to display a grand total of every column then we can use the ‘–total’ flag. Here is an example:
$ df -h --total
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             127G  6.0G  114G   5% /
tmpfs                 3.9G     0  3.9G   0% /dev/shm
/dev/sdb2              30G  115M   28G   1% /home/oracle
/dev/sdc1             550G   70M  522G   1% /home/data
total                 710G  6.2G  668G   1%
So we see that a new row ‘total’ at the end of the output was produced.



No comments:

Post a Comment