[TriLUG] how to test `du $SOURCE` < `df $TARGET` ?

Tom Roche Tom_Roche at pobox.com
Sun May 25 13:08:28 EDT 2008


I'm guessing this is a FAQ, but my search terms aren't finding :-(

Suppose you're scripting the writing of a buncha stuff from a source
filesystem to a target, and you wanna fail fast if there's not enough
space on the target. I can do, e.g.

$ du -c ${SOURCE}
3834530 total
$ df ${TARGET}
Filesystem           1K-blocks      Used Available Use% Mounted on
d:                     4581248       354   4580894   1% /d

then parse the output and do something like

if [ "${TARGET_FREE_BLOCKS}" -gt "${SOURCE_USED_BLOCKS}" ]

But I'm thinking there's gotta be a {better, easier, more robust} way
to do this. Is there?

TIA, Tom Roche <Tom_Roche at pobox.com>



More information about the TriLUG mailing list