Operating System - HP-UX
1833405 Members
2983 Online
110052 Solutions
New Discussion

Re: Simple 'find' command question

 
SOLVED
Go to solution
Darrell Tyler_1
Advisor

Simple 'find' command question

Hello,
Is there a way of issuing the 'find' command to poll for â file ownerâ ? I have tried the below command with no luck

# find /home -user *ftp*
find: missing conjun
12 REPLIES 12
RAC_1
Honored Contributor

Re: Simple 'find' command question

I think it has to be
find /home -user ftp

Anil
There is no substitute to HARDWORK
Mark Grant
Honored Contributor

Re: Simple 'find' command question

You can't use the '*' around the user name.

It would need to be "find /home -user ftp".
Never preceed any demonstration with anything more predictive than "watch this"
Solution

Re: Simple 'find' command question

you should not have the * around the username. The shell will interpret the * as a wildcard before executing the find command. so what you want is:

find /home -user ftp -type f -exec ls -l {} \;
Anupam Anshu_1
Valued Contributor

Re: Simple 'find' command question

With -user option of commands you can give only +/- i.e.

find /home -user +101
find /home -user -101
find /home -user 101

find doesn't allow regular expressions for option to -user.
Anshu

Geoff Wild
Honored Contributor

Re: Simple 'find' command question

Yes - can not have *'s

-user uname True if the file belongs to the user uname.
If uname is numeric and does not appear as a
login name in the /etc/passwd file, it is
taken as a user ID. The uname operand can be
preceded by a + or - to modify the comparison
of the primaries. If the argument n
represents a decimal integer; +n means more
than n, -n means less than n, and n means
exactly n.



find /home -user ftp


Find only user with uis 21100
or find /home -user 21100

Find all users greater then uid 21099
or find /home -user +21099

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Robert-Jan Goossens
Honored Contributor

Re: Simple 'find' command question

Anshu,

That is not right,

# cd /home
# find . -user gorj -type f -exec ll {} \;
-rwxr-xr-x 1 gorj users 65 Apr 20 13:03 .history
-rwxr-x--- 1 gorj users 341 Jun 13 2000 .login
-rw------- 1 gorj users 19124 Mar 25 10:51 .lsof
-rwxr-x--- 1 gorj users 1768 May 17 09:46 .profile

regards,
Robert-Jan
Mel Burslan
Honored Contributor

Re: Simple 'find' command question

if what you are doing is to find files owned by users who has the word ftp as a part of their username, you can do this

for username in `cat /etc/passwd | cut -d: -f1 | grep ftp`
do
find /home -user $username
done

Hope this helps
________________________________
UNIX because I majored in cryptology...
Jose Mosquera
Honored Contributor

Re: Simple 'find' command question

Hi,

Try the following lines:

USERS=`cat /etc/passwd|awk -F":" '{ print $1 }'|grep ftp`
for USER in $USERS
do
find /home -user $USER
done


If you need more information about found files replace previously "find" sintax by this:
find /home -user $USER -exec ll {} \;

BR.
Darrell Tyler_1
Advisor

Re: Simple 'find' command question

Hello again,
I want to thank you all for the information and perspective you have afforded me. I think of all, Mel Burslan is the closest to what Iâ m looking for - files that have ftp as a part of their owner
iminus
Frequent Advisor

Re: Simple 'find' command question

Try find /home -user ""

you can specify wild card * for searching in the quotes.
hope it helps
Dani Seely
Valued Contributor

Re: Simple 'find' command question

Hey Darrell,
Based on your example you used in your question, Iminus was closest to your answer.

If you are looking for any user with ftp in the name (i.e. tftpuser) you would need to enclose the ftp in quotes with an asterisk before and after ...
# find /home -user "*ftp*"

If you are looking for a user with ftp in the name then you don't need quotes, you would use:
# find /home -user *ftp

Same for the reverse ... ftp, you would use:
# find /home -user ftp*

Your example shows two asterisks, so you would use the first example I show above.

Good luck!
Together We Stand!
Darrell Tyler_1
Advisor

Re: Simple 'find' command question

Thank you once again!