The Storage Hunt
When an Ubuntu Linux server runs out of hard drive space, the entire operating system can crash. Often, the culprit is not a million tiny files, but a single, massive fileāsuch as a runaway error log or an abandoned database backup that has swollen to 50 Gigabytes. Manually clicking through directories with the ls command to find these massive files is impossible. You must instruct the Linux search engine to filter the entire filesystem strictly by the byte size of the documents.
Using the find Command with -size
The Linux find command utilizes the -size flag to search for files based on exact, greater-than, or less-than mathematical parameters.
- Open your Terminal application (Ctrl + Alt + T) or log into your server via SSH.
- To search the entire
/var/log/directory for any files that are larger than 1 Gigabyte, type the following command exactly: sudo find /var/log/ -type f -size +1G- Press Enter and provide your administrator password.
Understanding the Syntax
The syntax of the -size flag is very strict. The plus sign (+) means “greater than.” If you used a minus sign (-1G), it would find files smaller than 1 Gigabyte. The capital G stands for Gigabytes. You can also use M for Megabytes (e.g., -size +500M to find files larger than 500 MB) or k for kilobytes (must be lowercase). This command will instantly print a list of the largest files on your server, allowing you to quickly delete them and restore your server’s stability.