How to Find All Files Owned by a Specific User in Ubuntu Linux

The User Permission Maze

In Ubuntu Linux, every single file and directory is tightly bound to a specific user account for security purposes. If you are a system administrator cleaning up a server after an employee leaves the company, or if you are trying to hunt down rogue files created by a compromised service account (like www-data), you need to map out exactly what that user owns. Attempting to click through folders and manually check the “Properties” of every file is impossible on a massive server. Instead, you can use the terminal to instantly scan the entire hard drive and generate a list of every file tied to a specific username.

Using the find Command with -user

The standard Linux find command includes a powerful filtering flag designed exactly for this scenario: -user.

  1. Open your Terminal application (Ctrl + Alt + T) or log into your server via SSH.
  2. Decide where you want to start the search. To search the entire hard drive, use the root directory (/).
  3. Type the following command:
  4. sudo find / -type f -user username (Replace “username” with the actual account name, such as johndoe or mysql).
  5. Press Enter and provide your administrator password.

How the Command Works

  • sudo is absolutely required here; without it, the command will be denied access to system folders and fail to find all the files.
  • / tells the system to start at the very top of the file hierarchy.
  • -type f restricts the output to actual files, ignoring directories (if you want to find folders owned by the user, change this to -type d).
  • -user is the critical filter that matches the file ownership metadata against the username you provided.

Dealing with Deleted Users (Orphaned Files)

If you have already deleted the user account using userdel, the files they created will still exist on the hard drive, but they will no longer be associated with a valid username; they will only show a raw numerical User ID (UID). To find these “orphaned” files, you must use a different flag:

  1. sudo find / -nouser

This command will scan the drive and list every single file that is owned by a ghost UID that no longer exists in the system’s user database, allowing you to safely delete them or reassign them to a new owner.

Get the best tech tips delivered straight to your inbox.

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