Operating System - HP-UX
1754340 Members
5013 Online
108813 Solutions
New Discussion юеВ

Re: How to find out files with unkown user name and group name?

 
Zhang Zhao gui
Frequent Advisor

How to find out files with unkown user name and group name?

I want to change the ownership and group name for those
orphaned files without specified name in /etc/passwd (they are displayed as
unknown numbers)
I can use "find -user +300 -exec ls -l {} \; " to find
out those files with unknown user ID but cannot
do the same thing for those files with unknown group ID. Because "find -group
+300 -exec ls -l {} \; " will
not work. Anybody got any idea?
2 REPLIES 2
Vitek Pepas_1
Occasional Advisor

Re: How to find out files with unkown user name and group name?

You want to find all files with numbers instead of user id, so use script
similar to following as an argument of -exec option.

find . -exec check_user {} \;

check_user:

#/usr/bin/ksh
ls -l $1 | read RERM LINKS USER GROUP THEREST
[[ $USER = [0-9][0-9][0-9] ]] && echo "$1 - user unknown: $USER"

Add corresponding line for checking group id.
Zhang Zhao gui
Frequent Advisor

Re: How to find out files with unkown user name and group name?

I think it will not work if I put check_user into the same script as where find
command is and call it as a
subroutine "check_user()". I can only get it done
after I put check_user in a separate script file and
specify the pathname after "find -exec", that is,
find -exec /tmp/check_user {} \;

But it is very slow. I found a better solution by using "-nouser" or "nogroup"
option in "find" command.