To find files owned by a specific user on Linux, you can use the find
command with the -user
option. Here’s an example command that finds all files in the home directory of user “username”:
find /home/username -user username
In this command, replace “username” with the actual username you want to search for. The command searches the directory “/home/username” and all its subdirectories for files owned by the user “username”.
You can also use the locate
command to find files owned by a specific user. The locate
command searches a database of all files on the system, so it can be faster than find
for large file systems. Here’s an example command that finds all files owned by user “username” using the locate
command:
locate -r "/home/username/.*" | xargs ls -l | awk '{if ($3 == "username") print}'
In this command, replace “username” with the actual username you want to search for. The locate -r
command searches for all files in the directory “/home/username” and its subdirectories, and pipes the results to the ls -l
command to display the file permissions and ownership. The awk
command filters the output to show only files owned by the user “username”.
Note that the locate
command uses a database that is updated periodically, so it may not show very recent file changes. If you want to search for very recent files, use the find
command instead.