How to Find Files by Group and Change Their Group Ownership in Ubuntu (find -exec chgrp)

The Ownership Reassignment Protocol

When reorganizing an Ubuntu Linux server’s internal departmental structure, you frequently need to reassign file ownership en masse. For example, if a legacy user group named marketing_old is being deprecated, you must locate every single file owned by that group across the entire filesystem and instantly assign those files to the new marketing_new group. If you simply run chgrp recursively on a top-level directory, you will overwrite the ownership of everything, including files owned by root or sysadmin. You must instruct the search engine to mathematically isolate the files based on their current group ID before executing the transfer.

Using the find Command with -group and -exec

The Linux find command allows you to chain the -group filter directly to the -exec action flag to run the group-change command (chgrp) strictly against the matched files.

  1. Open your Terminal application (Ctrl + Alt + T) or log into your server via SSH.
  2. To scan the /mnt/storage/ directory for all files currently belonging to the marketing_old group and instantly transfer their ownership to the marketing_new group, type the following command exactly:
  3. sudo find /mnt/storage/ -type f -group marketing_old -exec chgrp marketing_new {} \;
  4. Press Enter.

Targeted Execution Syntax

The -exec payload operates sequentially. The engine first identifies a file that is positively owned by marketing_old. It then triggers the chgrp marketing_new command. The curly braces {} act as a dynamic variable, forcing the find command to inject the absolute path of the matched file directly into the chgrp execution string. Finally, the escaped semicolon \; terminates the command. This ensures that only the intended files have their group metadata rewritten, leaving the rest of the directory tree entirely untouched.

Get the best tech tips delivered straight to your inbox.

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