How to Find Files Belonging to a Specific Group in Ubuntu (find -group)

The Group Ownership Audit

In Ubuntu Linux, file permissions are divided into three categories: User (the owner), Group (a collection of users), and Others. When auditing a shared server—especially a web server where developers belong to a shared www-data group—you frequently need to verify that all the correct files have been assigned to the correct group. Searching for files based on the individual user who created them is often insufficient, as multiple different developers might have contributed to the same directory. You must explicitly filter the search engine based on the group ownership ID.

Using the find Command with -group

The Linux find command utilizes the -group flag to exclusively search for files that belong to a specific, mathematically defined Linux group.

  1. Open your Terminal application (Ctrl + Alt + T) or log into your server via SSH.
  2. To search the /var/www/ directory for every single file and folder currently owned by the www-data group, type the following command exactly:
  3. sudo find /var/www/ -group www-data
  4. Press Enter and provide your administrator password.

Ensuring Proper Access

The -group flag is essential for finding orphaned or misconfigured files. By utilizing the -not flag in conjunction with it (e.g., find /var/www/ -not -group www-data), you can instantly generate a list of files inside your web directory that were accidentally created by a root user and assigned to the wrong group. This allows you to immediately identify permission conflicts that are causing “403 Forbidden” errors on your web server and fix them using the chgrp command.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.