List files whose owner or group is numeric

I want to add a condition is my find command to include files/sub-directory whose owner or group is all numeric number.

My current find command is

find . \( -user root -o -user soham\)  -type f -exec ls -l {} \; 2>&1

---------- Post updated at 10:20 AM ---------- Previous update was at 09:47 AM ----------

Sorry the command is

find . \( -user root -o -user soham\)  -type f -exec ls -l {} \; 2>/dev/null

Do you mean group id and user id for numbers?

cat /etc/group

will show you what numbers to use, /etc/passwd has userids.

Example: user john is uid 633 and group 101:

find . -type f   \( -user 633 -o -group 101 \)

will start you going.

Note that these numbers are usually not portable between servers, some uid's are constant like root, but john's uid could be almost any number > 100.

Edit: the id command will help, too.

id john

will show the uid and the group(s) for the user named john. Some users may be in multiple groups

We have some files/directory which are owned by/having group which are numeric. I want to add this condition in find command.

Thx

If you have uid's/gid's showing as numeric in list (e.g. ls ) commands then it's (probably) because those uid/gid have been removed (deleted) from either /etc/passwd (or /etc/shadow ) and /etc/group respectively.

If you can reinstate the entries in those files then the system will translate them into human readable uid/gid and they will no longer appear numeric. They are only appearing numeric now because those numbers do not appear in the files and so cannot be made human readable. Perhaps the original owner's user account was deleted? Change the ownership of those files to a currently valid account.

If you are looking for files that belong to a userID or groupID that is not current in your system try -nouser or -nogroup

For example where userID 57484 does not exist in the system:

$ chown 57484:root mp.log
$ find . -type f \( -nouser -o -nogroup \) -ls
   397014      4 -rw-r--r--   1  57484    root          360 Mar 24 01:45 ./mp.log
2 Likes

Thanks. This is what I wanted. I do not know how I missed it from man pages !