There are times when you'll need to figure out the size of files or directories on your Linux system. This is especially important when you're trying to determine if a certain set of files or directories will fit on a particular backup medium.
The best tool to obtain this information is du, which is available on every Linux system. du is flexible and offers a variety of options. For example, it allows you to determine the size of the current directory and all subdirectories:
$ du -sh
Using du by itself displays the size of every subdirectory under the current directory--it summarizes and reports the data in human-readable format, such as 402 MB instead of 411012 bytes. You can also see the size of every file in every subdirectory by incorporating the "-a" option:
$ du -ah
In addition, you can use du in combination with grep to find a particular file size. If you're searching in a directory and suspect a file is growing extremely large, reduce the output of du to all files and directories 1 GB in size or larger with this command:
$ du -ah|grep -e '[0-9]G'