Operating System - HP-UX
1752781 Members
6543 Online
108789 Solutions
New Discussion юеВ

Re: What's wrong with this FIND command?

 
SOLVED
Go to solution
Don Bentz
Regular Advisor

What's wrong with this FIND command?

I am trying to find all files whose "group" is NOT oradvlp. What is wrong with this?:

find $DATADIR ! -group oradvlp -exec ls -l {} \;

It returns such lines as:
-rw-r----- 1 sched oradvlp 1222 Feb 13 2003 wires.dat021306.gz
-rw-r--r-- 1 sched oradvlp 3833 Dec 11 2002 wires.dat121009.gz
-rw-r----- 1 sched oradvlp 910 Dec 11 2002 wires.dat121209.gz

I know that the group id is a number, but when "ls" translates it back, doesn't it use that to find the group name in /etc/group?
Insecurity is our friend. It keeps you dependent.
11 REPLIES 11
Victor Fridyev
Honored Contributor
Solution

Re: What's wrong with this FIND command?

Hi,

Try this
find $DATADIR -type f ! -group oradvlp -exec ls -l {} \;

In your command you see files under directory, which doesn't belong to group oradvlp

In order to see only directories use
-type d and ls -ld {} \;

HTH
Entities are not to be multiplied beyond necessity - RTFM
Geoff Wild
Honored Contributor

Re: What's wrong with this FIND command?


Try this:

find $DATADIR ! -group oradvlp -print | xargs ls -l {} \;

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.
Fred Ruffet
Honored Contributor

Re: What's wrong with this FIND command?

$ find /etc ! -group sys -exec ls -ld {} \; 2>/dev/null | wc -l
727
$ find /etc -group sys -exec ls -ld {} \; 2>/dev/null | wc -l
432
$ find /etc -exec ls -ld {} \; 2>/dev/null | wc -l
1159
$ expr 727 + 432
1159

=> works perfectly here...

could you do "ls -n" (no gid convertion in output) and a "grep oradvlp /etc/group" ?

Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)
Don Bentz
Regular Advisor

Re: What's wrong with this FIND command?

Well, your solutions take care of the problem although I am still uncertain what is wrong with the original version. I guess I'll just be happy with the solution until I get a chance to review the lengthy "man" page when I have a day or so to digest it. Thanks again.
Insecurity is our friend. It keeps you dependent.
Geoff Wild
Honored Contributor

Re: What's wrong with this FIND command?

Note - the reason to use xargs instead of exec is right in the man page for find:

Note that output from find was piped to xargs(1) instead of using
the -exec primary. This is because when a large number of files
or directories is to be processed by a single command, the -exec
primary spawns a separate process for each file or directory,
whereas xargs collects file names or directory names into
multiple arguments to a single chmod command, resulting in fewer
processes and greater system efficiency.

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.
Sundar_7
Honored Contributor

Re: What's wrong with this FIND command?

Hi,

I would go with what Victor has suggested.

The filenames in the output doesnt include any directory name so I assume these files belong to the directory that is NOT owned by group oradvlp.

# find $DATADIR ! -group oradvlp -exec ls -ld {} \;

-- Sundar.
Learn What to do ,How to do and more importantly When to do ?
Mel Burslan
Honored Contributor

Re: What's wrong with this FIND command?

what is wrong with the original command is, it did not discriminate between files and directories, hence . (dot) character is included in the files to find expansion. When you executed an ls -l on the current directory, you have received the files which you were trying to exclude by ! -group phrase.

Hope this helps explaining the situation.
________________________________
UNIX because I majored in cryptology...
Don Bentz
Regular Advisor

Re: What's wrong with this FIND command?

Thanks, Geoff. I am always concerned about the amount of overhead associated with "find".
Insecurity is our friend. It keeps you dependent.
Fred Ruffet
Honored Contributor

Re: What's wrong with this FIND command?

I think Victor is the one ! :)

The directory that contains the files is probably not owned by group oradvlp. When you issue "ls -l" on it, you see those files.

If you only want files, use Victor's solution. If you want directories too, use "ls -ld" instead of "ls -l" (directory will be shown instead of their content)

Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)