The Ownership Audit
In Ubuntu Linux, every single file and directory is “owned” by a specific user account. For example, your personal documents are owned by your username, while the configuration files for your web server are typically owned by a hidden system user called www-data. If a developer leaves your company, or if you suspect a specific application is generating massive log files and filling up your hard drive, you need a way to isolate files based strictly on who owns them, ignoring the file names entirely. You can execute this targeted audit using the terminal.
Using the find Command with -user
The standard Linux find command includes a specialized flag designed to filter search results by ownership.
- Open your Terminal application (Ctrl + Alt + T) or log into your server via SSH.
- Determine the directory you want to audit. To search the entire server, use the root directory (
/). - To locate every single file owned by the web server (www-data), type the following command:
sudo find / -user www-data- Press Enter and provide your administrator password.
Refining the Search
Searching the entire root directory for a common user will generate a massive wall of text. You can combine the -user flag with other flags to make the search much more useful. For example, if you want to find all files owned by www-data that are specifically larger than 100 Megabytes, you would type:
sudo find / -user www-data -size +100M
This combined command instantly isolates massive, bloated files generated by the web server, allowing you to quickly locate and delete them to recover your storage space.