Pages

Wednesday, July 11, 2012

Du & Df



df command in linux allows to see the amount of disk space that is free on the partitions in the current system. This is by default shown in 1kb.

When we run df without any arguments

[root@vx111a ~]# df
Filesystem           1K-blocks      Used        Available      Use% Mounted on
/dev/sda6            19840892      653768     18162984   4%      /
/dev/sda10          12254928      2490072   9132300     22%   /dump
/dev/sda8            9920592        2572224   6836300     28%  /usr
/dev/sda7            39674192      2500572    35125736   7%   /soa

display information of all file system with mount points too

[root@vx111a ~]# df -a
Filesystem           1K-blocks      Used      Available    Use% Mounted on
/dev/sda6             19840892    654200  18162552   4%      /
/dev/sda10            12254928   2490072 9132300    22%    /dump
/dev/sda8              9920592   2572224   6836300    28%    /usr
/dev/sda7             39674192   2500572  35125736   7%     /soa

Normally we see the memory in 1kbs.we can change this options to show the memory in a different way like

[root@vx111a ~]# df -B 1000
Filesystem          1kB-blocks      Used      Available    Use% Mounted on
/dev/sda6             20317074    669975   18598380   4%     /
/dev/sda10            12549047   2549834  9351476     22%  /dump
/dev/sda8             10158687   2633958  7000372      28%  /usr
/dev/sda7             40626373   2560586  35968754   7%   /soa

Here we have specified the block size as 1000.

If we need to have them in human readable format , we can use

[root@vx111a ~]# df -h
Filesystem         Size     Used    Avail   Use% Mounted on
/dev/sda6           19G    640M   18G     4%     /
/dev/sda10          12G    2.4G    8.8G    22%  /dump
/dev/sda8            9.5G   2.5G    6.6G    28%  /usr
/dev/sda7            38G    2.4G    34G      7%  /soa

We can get the file system type too using

[root@vx111a ~]# df -T
Filesystem    Type   1K-blocks      Used        Available   Use% Mounted on
/dev/sda6     ext3     19840892    654532    18162220   4%    /
/dev/sda10    ext3    12254928    2490072   9132300   22%    /dump
/dev/sda8     ext3     9920592      2572224   6836300   28%    /usr
/dev/sda7     ext3     39674192   2500572    35125736   7%   /soa

du: This command is normally used for estimating the file space usage

[root@vx111a test]# du -h
64K

du -h displays the amount of space used by the current directory .

If we need to get more detail about the files in the current directory, we can use

[root@vx111a test]# du -ah
8.0K    ./file2
8.0K    ./file3
16K     ./sam
8.0K    ./anaconda-ks.cfg
8.0K    ./file1
8.0K    ./sample
64K     .

If we need just the total amount of space used, we can

[root@vx111a test]# du -c
64      .
64      total

There will be some stages where you want to provide du with a input .in that case we can use ‘du -ah --files0-from=-‘.When you run this command , you will be given a cursor to enter input, enter any file name in the current directory like

du -ah --files0-from=-
sam 16K  sam

Once you enter the file, press ctrl + d twice in order to produce the output of the file.

du provides us an options which allows to exclude particular files , we can use

[root@vx111a test]# du -cbha --exclude="*.txt"
14      ./file2
14      ./file3
9.4K    ./sam
1.4K    ./anaconda-ks.cfg
14      ./file1
17      ./sample
15K     .
15K     total

More to Come, Happy Learning J