You have looked at determining the amount (Best web hosting) of

You have looked at determining the amount of disk space available in a directory, but sometimes you need to know how much disk space a directory uses. For example, you might have a public directory that needs to be cleaned out when it exceeds a certain size. To perform this task, you need to use the du ( du as in disk usage) command. Because you want the output for an entire directory and its contents, you need to specify the -s ( s as in sum) option to du. You also need to specify the -k ( k as in kilobyte) option for a consistent output on all versions of UNIX. The output of the du -sk command looks like the following: $ du -sk /home/ranga/pub 4922 /home/ranga/pub The size of the directory in kilobytes is listed in the first column. Your function uses awk to obtain this number. ################################################ # Name: getSpaceUsed # Desc: output the space used for a directory # Args: $1 -> The directory to check ################################################ getSpaceUsed() { if [ $# -lt 1 ] ; then printERROR “Insufficient Arguments.” return 1 fi if [ ! -d “$1″ ] ; then printERROR “$1 is not a directory.” return 1 fi du -sk “$1″ | awk ‘{ print $1 ; }’ } This function is almost as simple as getSpaceFree. It first checks whether it was given an argument. If no argument was given, it displays an error message and returns. Otherwise, it checks to see whether the first argument is a directory. If it is not, an error message is displayed and the function returns. Otherwise, the function executes the du -sk command and displays the number stored in the first column. As an example of using this function, the command getSpaceUsed /usr/local displays the following value on my system: 15164
If you are in need for chaep and reliable webhost to host your website, our recommendation is http web server services.

Leave a Reply