Stange node title isn't it. It's actually a Unix command - but don't tune out just yet - with the information stored in this node, you have the chance to impress someone who uses Unix with this less well known yet incredibly useful command.

The man (or help) pages for this command are very precise, but not much help in determining the context with which to use it.

"The du utility displays the file system block usage for each file argu- ment and for each directory in the file hierarchy rooted in each directo- ry argument. If no file is specified, the block usage of the hierarchy rooted in the current directory is displayed. If the -k flag is speci- fied, the number of 1024-byte blocks used by the file is displayed, oth- erwise getbsize(3) is used to determine the preferred block size. Par- tial numbers of blocks are rounded up."

See what I mean? Kinda dry isn't it. Now let me explain where this command comes in handy.

Anyone who uses Unix for a while whether it be on a single user basis using Linux or some big telco system running IBM AIX, we come across a need to determine the total amount of data contained in a directory including its subdirectories. Maybe you need to find which directory is using up the most space, or maybe you have a directory with a hundred sub-directories and you need to know the total amount of disk that the directory is taking up ... all of this can be determined using the du command. Here are two examples of how to use the command:

How many Mbytes is that directory (and all it's subdirectories) consuming?
For example, say I have the folling directory structure with each directory containing tens of mp3 music files:

       |           |-Mozart
       |           |-Handel
       |     |-Corrs-|
       |     |       |-InBlue
       |     |       |-FnF
       |     |       |-ToC
       |     |       
       |     |-bryanadams
To find out how many Mbyte of data I have in mp3s, I would type the following command: du -sk mp3s This will give me a single number which will be the total amount of data in kbytes (that's what the -k option is for), stored in the mp3s directory and all the subdirectories under it (ie classical, handel, InBlue etc).

Which directory is taking up the most space?
Say I discover that I need to free up some space in my /home filesystem. I may have 1000 users and I want to delete files from those users who are using the most space. This is very easy to do. I would 'cd /home' and then type: du -sk * This will examine every directory in /home and report back a list of usernames with a single number after it which would represent the amount of data in kbytes that they had. eg here is a sample output:

390     awhitloc
728     ghemming
825     aludwell
1131    jwinton
1740    fgenua
1788    spryor
2041    sbachelo
3199    ltsorbar
4605    rkelly
12074   mhutchis
20211   srymer
Notice how the results have been sorted into decending order. Well like most Unix commands, you can combine them together. So to achieve the sorted results, I typed: du -sk * |sort -n. In the example above, user srymer is using the most space on my system (he's using about 20 Mbyte of space). So with this commmand you can easily find out which directories have betrayed you, filled your filesystem and caused you grief :).

So there you have it! A quick intro into one of the most useful and less known commands in the Unix command language. If you want to find out more, type in 'man du' or 'man sort' at your friendly local Unix prompt.

Log in or registerto write something here or to contact authors.