Operating System - HP-UX
1834387 Members
2386 Online
110066 Solutions
New Discussion

using the find command instead of writing a script

 
SOLVED
Go to solution
john guardian
Super Advisor

using the find command instead of writing a script

I could write a script, but thought there might be an easier approach using a single line "find" cmd. Is there an easy method using "find" to list 3 users home dirs with files ( for example /home/moe, /home/larry and /home/curly), then take the output of the find cmd to list the dir and files within without also displaying all the nonsense like "total 8" etc for each dir/subdir?

The end result I'm shooting for is use find to extract a list of all dirs/files in each user's home dir and display/list the GID rather than the group name in the listing.

Any ideas?

Thx.
6 REPLIES 6
Patrick Wallek
Honored Contributor
Solution

Re: using the find command instead of writing a script

How about something like this:

find /home/moe /home/larry /home/curly | xargs ls -ldn

The 'ls -ldn' will do a long listing, not traversing a directory, and will substitute the uid/gid rather than the username and group name. If you just want the file name and gid:

find /home/moe /home/larry /home/curly | xargs ls -ldn | awk '{print $4,$9}'
James R. Ferguson
Acclaimed Contributor

Re: using the find command instead of writing a script

Hi JOhn:

I might do:

# find /home/moe /home/larry /home/curly -exec ls -ln {} + | awk '{print $3,$4,$NF}'

Using the '+' terminator to find()'s '-exec' argument eliminates the 'xargs' process but creates a very large argument list for every instantiation of the 'ls' process, thereby optimizing performance.

Regards!

...JRF...

Dennis Handly
Acclaimed Contributor

Re: using the find command instead of writing a script

>JRF: find /home/moe /home/larry /home/curly -exec ls -ln {} + | ...

You'll need to add -d so you don't list the directories twice:
... -exec ls -ldn {} + | ...
James R. Ferguson
Acclaimed Contributor

Re: using the find command instead of writing a script

Hi (again):

Dennis: You'll need to add -d ...

Yes, of course (dummy me); thanks.

BTW, John: When does a command-line "script" [ which to me is more than one builtin command or external executable ] become a "full script" ? :-) Everything is relative and depends partly on how much you want/can pack onto a command-line.

Regards!

...JRF...
Steven Schweda
Honored Contributor

Re: using the find command instead of writing a script

> [...] When does a command-line "script" [
> which to me is more than one builtin
> command or external executable ] become a
> "full script" ?

Some (perhaps many) would say: When it's in a
file of its own.

Multiple commands on one command line is
often called a "list" or a "pipeline", but
check your shell documentation for the
details.

man sh
man [...]


Sometimes terms like these are actually
defined in the documentation, and while one
is always free to create one's own
definitions, there are advantages to using
standard ones.
john guardian
Super Advisor

Re: using the find command instead of writing a script

Thx to all. I have used input to create what I needed.

Cheers to everyone who added positive info/input. My sincere appreciation.

Jeers (and 1 point) to the individual who had nothing positive to add, excepting command of the English language.

Once again, much appreciated.