Disk+Usage+on+Unix

du (disk usage) lists the size of the directory you're in and the size of every subdirectory in kilobytes.

If you want to skip all the details, and just see the command line I recommend, go down to the bottom.

du --max-depth=N displays only N levels of subdirectories below the directory where the command is run. This keeps the output readable when there is a big directory structure.

Here's an example output: code >du --max-depth=1 396 ./NWispSpCntr_NoComm_05JUL2008b 76572 ./ReaderAssistant 1.0.12 304 ./NWisp000_CommWorking 1608 ./2008-07-06-NeuralWisp 57720 ./Old Install Files 136604 . code

du -h uses "human readable" units, so that 21784 becomes 22M and 1349664 becomes 1.3G, etc, which improves readability for large numbers.

code >du --max-depth=1 -h 396K ./NWispSpCntr_NoComm_05JUL2008b 75M ./ReaderAssistant 1.0.12 304K ./NWisp000_CommWorking 1.6M ./2008-07-06-NeuralWisp 57M ./Old Install Files 134M. code

du -B 1M uses a "block size" of 1MB (2^20). Other possibilities are kB=1000, K=1024, G=2^30. Directory sizes are rounded up. This will be useful if you want to use sort (see below). If you use an integer in the block size specification, the size will just be the numbers, but if you just use K, M, etc., du will append the block size specifier onto the sizes.

Examples:

code >du --max-depth=1 -B M 1M ./NWispSpCntr_NoComm_05JUL2008b 75M ./ReaderAssistant 1.0.12 1M ./NWisp000_CommWorking 2M ./2008-07-06-NeuralWisp 57M ./Old Install Files 134M.

>du --max-depth=1 -B 1K 396 ./NWispSpCntr_NoComm_05JUL2008b 76572 ./ReaderAssistant 1.0.12 304 ./NWisp000_CommWorking 1608 ./2008-07-06-NeuralWisp 57720 ./Old Install Files 136604 . code

The order of the output is arbitrary, so finding the big disk hogs is a bit of a pain. There is another unix utility, sort, which can help with this. Use the pipe operator "|" to send the output from du to sort.

"sort" sorts lines of a text file. The default is to use alphanumerical order, which means that 134 comes between 1 and 2.

code >du --max-depth=1 -B 1M | sort 1 ./NWisp000_CommWorking 1 ./NWispSpCntr_NoComm_05JUL2008b 134 . 2 ./2008-07-06-NeuralWisp 57 ./Old Install Files 75 ./ReaderAssistant 1.0.12 code

sort -n uses a numeric sort, which fixes this problem. This is the command line I would recommend using.

code >du --max-depth=1 -B M | sort -n 1M ./NWisp000_CommWorking 1M ./NWispSpCntr_NoComm_05JUL2008b 2M ./2008-07-06-NeuralWisp 57M ./Old Install Files 75M ./ReaderAssistant 1.0.12 134M. code

It doesn't really matter whether you use M or 1M for the size, but if you use '-h', sort will not know how to interpret the K,M,G, etc., so it is important that all the sizes have either the same suffix, or no suffix.

If you have a lot of cleaning up to do, you may want to redirect the output to a file, so it doesn't scroll off the top as you start removing clutter.

code >du --max-depth=1 -B 1M | sort -n > du_output.txt code

If you only want to see the last few lines, you can use the "tail" utility, which displays only the last few lines of its output. This line will show your 5 biggest directories: code du --max-depth=1 -B M | sort -n | tail -n 5 code

Finally, if you use tcsh, you can add this line to your .aliases or .cshrc.local file and you won't have to remember all the options:

code alias disk_usage 'du --max-depth=1 -B M | sort -n' code

To see how much space is left on a disk, use df. It also accepts the -h option. It also accepts an optional argument of a path, which will give the information for the disk containing that path. Examples: code >df Filesystem          1K-blocks      Used Available Use% Mounted on /dev/sda1              8064272   4160372   3494248  55% / none                  1027920         0   1027920   0% /dev/shm /dev/sda7           275311064 111032156 150293928  43% /s0 /dev/sda5             1004024     17720    935300   2% /tmp /dev/sda3             1035692    331168    651912  34% /usr/vice/cache /dev/sda6             1004024    193032    759988  21% /var AFS                   9000000         0   9000000   0% /afs vlsifiles:/d1       1206332800 630922144 563155040  53% /atm/vlsifiles/d1

>df -h. Filesystem           Size  Used Avail Use% Mounted on vlsifiles:/d1         1.2T  602G  538G  53% /atm/vlsifiles/d1

>df -h /s0 Filesystem           Size  Used Avail Use% Mounted on /dev/sda7             263G  106G  144G  43% /s0

code You could use this if you want to know whether the disk is about to fill up a few days before tapeout.

This command is available on all Nikola linux systems. Its intent is to let a user know which nikola hosts he or she has requested a directory in /s0 or /s1 on. It can be run from any Nikola linux system.

Here's the manpage:

SDU(8) NIKOLA System Administrator’s Manual SDU(8)

NAME sdu - Scratch Disk Usage lister

SYNOPSIS /usr/nikola/bin/sdu [ -u user ]

DESCRIPTION sdu Lists scratch directories the user has a directory in. It will list only for hosts marked online in the machine database.

If called with the -u name arguments, it lists that users’s space. Default is to list the space for the user who called it.

NOTES Output is based on machine database files which are generated nightly. Removing a scratch directory won’t be reflected in the output of sdu until the next day.

SEE ALSO space_req(1), space_unreq(1)