Commands.page Logo

How to Find Files Owned by User ID in Ubuntu Linux

This article provides a direct method for locating every file associated with a specific numerical user ID on an Ubuntu system. You will learn the essential command-line syntax required to scan directories efficiently. The guide covers system-wide searches and how to manage permission restrictions during the process.

To locate files based on a user ID rather than a username, you should use the find command with the -uid option. This is particularly useful when dealing with orphaned files or when you know the numerical ID but not the associated username. Open your terminal to begin the search.

For a system-wide search, you need to start from the root directory. Since many directories require elevated privileges to scan, you must use sudo. Run the following command, replacing 1000 with the specific user ID you are investigating:

sudo find / -uid 1000

This command searches every directory from the root (/) downwards. It may take some time to complete depending on the size of your storage and the speed of your drive. The output will list the full path of every file owned by that specific user ID.

If you only want to search within a specific directory, such as a user’s home folder, change the path from / to the desired location. This speeds up the process and reduces permission errors. For example, to search only within /home:

sudo find /home -uid 1000

To make the output more informative, you can combine the -uid flag with -ls. This displays detailed information about each file, including permissions, size, and modification date, similar to the ls -l command:

sudo find / -uid 1000 -ls

If you encounter many “Permission denied” errors even while using sudo, you can redirect standard error to null to keep the output clean. This hides the error messages and shows only the found files:

sudo find / -uid 1000 2>/dev/null

Using these commands allows you to effectively audit file ownership on your Ubuntu machine using the numerical user ID.