1833778 Members
2290 Online
110063 Solutions
New Discussion

Re: Problems with find

 
SOLVED
Go to solution
Pete Kelly
Frequent Advisor

Problems with find

Hi there..

I am using the find command to search in a specific directory for files owned by a user.
"find /(dir) -user (user) -print -exec ls -l {} \; > /tmp/file" is the command i'm using.

When I check the /tmp/file file, there are files in there that are owned by root! not just the (user) user.

If I replace the ls -l with a chown (newuser), the files belonging to root would be chown'd to the newuser.

Am I having a "blonde moment" here... HELP
14 REPLIES 14
Joseph Loo
Honored Contributor

Re: Problems with find

try:

# find / -user -exec ls -ld {} \;
e.g.
# find /tmp/ -user root -exec ls -ld {} \;

the above will only show the files belonging to the specified username or UID. check if UID of root is co-own by another users.

# logins -u

regards.
what you do not see does not mean you should not believe
Bharat Katkar
Honored Contributor

Re: Problems with find

Try Executing this one, i have tested and it works:

find /dir) -user (user) -print > /tmp/file

No need for exec.

Hope that helps.
Regards
You need to know a lot to actually know how little you know
KapilRaj
Honored Contributor

Re: Problems with find

What is the user's UID ?. Is it "0" (zero) ?.

Kaps
Nothing is impossible
Joseph Loo
Honored Contributor

Re: Problems with find

by the way, I think you have forgotten your promise to assign points for the previous post, .

regards.
what you do not see does not mean you should not believe
Chris Wilshaw
Honored Contributor

Re: Problems with find

My guess would be that there's on or more subdirectories that are owned by your user, and that when the ls is executed, it does an ls on that subdirectory, displaying the entire contents.

Try

find /dir -user (user) -type f -exec ls -l {} \;
Bharat Katkar
Honored Contributor

Re: Problems with find

Have a look at /etc/passwd file and look for 3rd field UID of the users. Have you by mistake given UID 0 to any other users?

Regards,
You need to know a lot to actually know how little you know
Pete Kelly
Frequent Advisor

Re: Problems with find

Many thanks for the prompt replies. I'm trying out a couple of the suggestions now.

I will be sorting out the points problem from my previous post very soon.

The user in question is currently set at UID 99, and I'm looking to increase the UID to 199
Victor Fridyev
Honored Contributor
Solution

Re: Problems with find

Hi,

I think, the problem is in ls -l:
Your find gives you not only files but directories as well. If in a directory, which belongs to the (user) there are files which belongs to root, you see them in the output.
Add additional option into your find command:
find (dir) -type f

HTH
Entities are not to be multiplied beyond necessity - RTFM
Bruno Ganino
Honored Contributor

Re: Problems with find

Try this
find /(dir) -type f -user (user) -print > /tmp/file
HTH
Bruno
Torino (Turin) +2H
Bharat Katkar
Honored Contributor

Re: Problems with find

Hi,
UID should be normally be above 100 because below 100 they are supposed to be used by System.

Hope that helps.
Regards,

You need to know a lot to actually know how little you know
Pete Kelly
Frequent Advisor

Re: Problems with find

Many thanks for all your replies to this query. As it turns out, I've been going up a blind alley. The UID's in question need to be kept as they are for application functionality. I'll be assigning points soon
John Carr_2
Honored Contributor

Re: Problems with find

Hi

just in case you ever do change the UID of a user you will need to do a recursive change of owner to the files they own too.

:-) John.
Kelsey Petrychyn
Occasional Advisor

Re: Problems with find

Hi Pete;

I think what is happening is that the find command has encountered a directory owned by (user) that in fact contains files owned by root.

ie.
".... -exec ls -l {}"

means do a long listing on whatever we just found (in this case a directory). Similar to if you had typed "ls -l /var".

I am not sure, but I think a chown will work as intended provided you don't use the "-R" option. However, I would test the new chown version on junk/test files first, before releasing it on unsuspecting important files.
Ross Barton
Occasional Advisor

Re: Problems with find

Pete,

Try using the find command with egrep -v to cull out the files owned by root. This will work whether the userid you are searching on shares the uid of 0 with root or not.

For example
find . -user ingres -type f -exec ls -l {} \; | egrep -v root

Cheers,
Rossco
Everything should be made as simple as possible, but not simpler. Albert Einstein.