Locate Large Files and Directories
Finding Large Directories
To find large directories, use the du command and sort the output.
For example, to output the 10 largest directories in /var, sorted in ascending size order, use the following command:
To avoid crossing file system boundaries, that is, to see the directory usage in / but not in the other mounted files systems (/var, /opt, and so on), add the d option to the du command:
Another super useful tool is ncdu. An ncurses disk usage viewer that provides a more user-friendly interface for navigating through directories and their sizes.
Finding Large Files
To find large files, use the find command and sort the output.
- Example 1: To find all plain files (not block, character, symbolic links, and so on) in a file system larger than 200,000 512-byte blocks (approximately 100 Mbytes) and sort on field 7 (file size) while numerically ignoring leading blanks, do this:
- Example 2: To find all plain files (not block, character, symbolic links, and so on) in a /var file system larger than 1,000 512-byte blocks (approximately 500 Kbytes) and sort on field 7 (file size) while numerically ignoring leading blanks, do this: