Need to know how much space a directory and its contents are taking up on your UNIX system? Here’s what I use:
du -ks directory
du command is used to summarize disk usage. Without any flags will show you the usage in blocks for every directory and subdirectory specified. Since the number of blocks varies by operating system we add the
-k option to specify that we want the output in kilobytes. In many operating systems you could also use
-h for a “human-readable” output with abbreviations like B for bytes, K for kilobytes, M for megabytes and so on.
-s option lets us gather only the sum of the directory specified. Without the
-s flag we would get output on every subdirectory as well as the specified directory.
$ du -k stuff
One other thing that is useful for finding the biggest files and directories where there are a lot to sift through is to use a wildcard to size up multiple directories, then pipe the output of
du to the
sort command like this:
$ du -ks ./* | sort -n
sort we use the
-n option to order things by arithmetic value rather than alphabetic value (making 8 come before 304) so we see the largest things at the bottom.
Try it out. As always check the
man pages for more info.
For more tips like this check out my book Easy Linux Commands, only $19.95 from Rampant TechPress.