Last Updated: 1/19/2016
This article applies to the following services:
- VPS (Linux only)
- Dedicated servers (Linux only)
If you are specifically looking for file and directory sizes, the `du` command is best suited for this task. Let's use /usr/local as an example.
du -h /usr/local/This will recursively output each directory in /usr/local with each directory's respective size. You can limit how deep the listing goes with a command similar to the following:
du -h /usr/local/* --max-depth=1This will only output the files and directories in /usr/local, and does not limitlessly output every single file and directory in /usr/local. The wildcard is necessary in this case since we're looking for the sizes in /usr/local/. If we were to omit the wildcard, the --max-depth=1 directive would have shown the size of the /usr/local directory itself. Another way to do this without using the wildcard is to say `--max=depth=2`. In this case, the output would have shown the size of /usr/local itself as well as the sizes of its contents.
The `-h` option we've been using in our example stands for "human readable". This means the output will shows sizes in the greatest possible unit. For example, instead of 400,000 KB, it will display as 400 MB. Or instead of 5,000,000 KB, it will display as 5 GB. There are other options you can use to force the unit to whatever you desire:
- -k = kilobyte (default)
- -m = megabyte
- -h = human readable
For more information on the du command, refer to its man page.