- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find Files Not Owned by a Specific User in Linux
A Linux system may consist of various users with different permissions. However, sometimes we need to find and access a specific user's files. So, in this case, you can use the find command to display the files owned by any other user.
The find commands let you search for a specific file in the directory. With this command, you can find the list of available files per the owner, type, and attributes, like a file name. The find command utility is pre-installed in almost every Linux distro.
So if you also want to find the file which a specific user owns, this guide is for you. In this guide, we will use the 'find' command to find files of specific users in Linux.
How to Find Files not Owned by a Specific User in Linux ?
Through the find command, you can list all the files that don't have any ownership or that don't belong to any user. First, please run the following command to list out all the files that don't have any user −
~$: find / -nouser find: '/etc/polkit-l/localauthority': Permission denied find: '/etc/cups/ssl': Permission denied find: '/etc/ssl/private': Permission denied find: '/root': Permission denied find: '/var/spool/postfix/flush': Permission denied find: '/var/spool/postfix/saved': Permission denied find: '/var/spool/postfix/maildrop': Permission denied find: '/var/spool/postfix/active': Permission denied
This lists all the files from the system that any user does not own. The find command contains the test negation to find files any user owns. It allows you to add a '!' before the test to negate the test expression. Through this, you can find those files which have no owner.
List out all the files that don't belong to any particular user with the following command −
~$: find ! -user
For example, here we list all the files not owned by the user named 'prateek.'
~$: find ! -user prateek ./.1ocal/share/Trash/files/test_results ./.1ocal/share/Trash/files/linux ./.1ocal/share/Trash/files/no-directory.txt ./.local/share/Trash/files/point $ I
As you can see from the above result, all those files are listed whose owner is not 'prateek.'
Wrapping Up
Find command helps you in searching any file in Linux. Similarly, in this guide, we use the find command to find files that do not have a specific owner. Finding a file owned by a user is easy because you only need to add the '!' with the command. We hope this guide will help you search all those files that any specific user does not own.