Saturday 28 January 2012

df


df
df command gives you the  information of the disk spaces. It is a very good command for
system administration and file system monitoring. You can also view  various parameters
like total number of files in a particular file system and maximum allocated values.

Reducing the space occupied by a file system helps to boost system performance by making
The applications and utilities that use these file systems take lesser time for accessing data,
So constantly running df helps.


Example 1)
df comes various options like -g,-m,-k etc which helps you to view file system sizes in gigabytes, megabytes or kilobytes blocks  resp , including t gives total allocated space.

Consider the output of df –gt.

/home/Prod$ df     –gt.
Filesystem                     GB blocks   Used   Free   Used Mounted on
/dev/hd4                            0.75   0.35   0.40    48% /
/dev/hd2                            5.50   3.68   1.82    67% /usr
/dev/hd9var                         4.00   0.63   3.37    16% /var
/dev/hd3                            4.62   0.71   3.91    16% /tmp
/dev/hd1                            8.25   3.96   4.29    48% /home
/dev/hd10opt                        4.50   1.30   3.20    29% /opt
/dev/lv00                           0.12   0.00   0.12     4% /var/adm/csd
/dev/fslv00                         5.00   0.03   4.97     1% /utilities
/dev/ora10g_lv                     15.00   5.18   9.82    35% /ora10g


The output of the command might not look organised in some unix systems.ie: alignment does not seems to be right,
Use awk for help.

/home/Prod$ df –gt | awk  'BEGIN{aa="Filesystem";bb="GB blocks";cc="Used";dd="Free";ee="Used";ff="Mounted on";printf("%-40s %9s %6s %6s %6s %-11s\n",aa,bb,cc,dd,ee,ff);} {if($1!="Filesystem"){printf("%-40s %9s %6s %6s %6s %-9s\n",$1,$2,$3,$4,$5,$6) } }'


Filesystem               GB blocks         Used           Free         Used           Mounted on
/dev/hd4                      0.75               0.35           0.40          48%           /
/dev/hd2                      5.50               3.68           1.82          67%          /usr
/dev/hd9var                4.00                0.63           3.37         16%          /var
/dev/hd3                      4.62               0.71           3.91          16%         /tmp
/dev/hd10opt             4.50               1.30           3.20          29%        /opt
/dev/lv00                     0.12               0.00            0.12          4%          /var/adm/csd
/dev/fslv00                  5.00               0.03           4.97          1 %         /utilitie/dev/hd1                     
/dev/hd1                      8.25               3.96           4.29          48%        /home
/dev/ora10g_lv          15.00             5.18           9.82          35%        /ora10g

Now ,that seems to be a much better organised output. Use this in a script and keep an
alias for df command to this script named df.

Example 2)
To constantly monitor disk space you can make a script and run it constantly.
/home/Prod$ cat  disk-monitor.sh
#!/usr/bin/ksh
for   Pspace  in  `df   -gt  | awk  ‘{ print $4}’  | grep –v   -e used   -e  /ora  |  tr  -d  ‘%’ `
do
if  [  $ Pspace   -gt    80  ]
then
alarmfunc                  #call the alarm function.
fi
done




Example 3)
 df is also helpful in knowing  number of files present in a mount  point.
It is also referred to as Inode. For all all the file system mount points  there is a
Inode value assigned which gives the maximum  number of files that can be placed in the file system. When the number of files exceed too a large value, you get  ‘parameter list is too long’
error with commands that use wildcards as  arguments to filename.

Every file has  an inode value of 1 and a directory has  an inode value of 2.

To see the Inode values along with other attributes,use df  –i, and off course with  awk filtering.(Use different values before  %s for proper alignment)

 /home/Prod$ df  -i
Filesystem  512-blocks             Free            %Used      Iused        %Iused     Mounted on   
/dev/hd0    19368                     9976            48%          4714            5%             /           
/dev/hd1    24212                     4808            80%          5031            19%        /usr        
/dev/hd2     9744                        9352            4%           1900            4%         /site       
/dev/hd3     3868                       3856            0%            986              0%          /tmp
 /dev/hd1    56890                     23409          41%         2345           40%        /home        
                                                                                         |                                    
                                                              Here is the number of files present in your home path,which
Is 40% of total allocated value. So periodically archive or remove  the unwanted files.

No comments:

Post a Comment