AIX/Linux - User/Group ownership find commmand

I have a specific user and group (adm4:admgrp4). I would like to search recursively for adm4:admgrp4 in a directory and get the output. I would like to review the output file of which directory and files adm4:admgrp4 own. Any ideas?
AIX25Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

woolmilkporcCommented:
Hi again!

You have the choice to create 4 distinct reports, namely

- files owned by user adm4
- directories owned by user adm4
- files owned by group admgrp4
- directories owned by group admgrp4

Or you can combine user and group and distinct just between directories and files, or combine directories and files and  distinct just between user and group, and filnally you can create one big report on files and dirs owned by user or group.

The single reports:

find /start/dir -type f -user adm4 -ls
find /start/dir -type d -user adm4 -ls
find /start/dir -type f -group admgrp4 -ls
find /start/dir -type d -group admgrp4 -ls

The file/dir distinction:

find /start/dir -type f  \( -user adm4 -o -group adm4grp \) -ls
find /start/dir -type d  \( -user adm4 -o -group adm4grp \) -ls

The user/group distinction:

find /start/dir \( -type f -o -type d \) -user adm4 -ls
find /start/dir \( -type f -o -type d \) -group adm4grp -ls

The whole picture:

find /start/dir \( -type f -o -type d \) -a \( -user adm4 -o -group adm4grp \) -ls

I added "-ls" at the end of each find command so it will produce an "ls" like output.

We could shorten the ouput lines to contain fewer info. Under AIX this requires using "awk" because "find" does not have the "-printf" action here.
Please let me know if this is an option.


wmp
0
woolmilkporcCommented:
A version just showing filename (spaces allowed), user and group:

find /start/dir \( -type f -o -type d \) -a \( -user adm4 -o -group adm4grp \) -ls |\
 awk '{for(i=11;i<=NF;i++) {printf  "%s ", $i}; printf "\t%s %s\n", $5, $6;}'
0
AIX25Author Commented:
woolmilkporc, thank your for you input! I have used the following options provided by you below, and it has provided the output I needed.

find /start/dir \( -type f -o -type d \) -a \( -user adm4 -o -group adm4grp \) -ls |\
 awk '{for(i=11;i<=NF;i++) {printf  "%s ", $i}; printf "\t%s %s\n", $5, $6;}'  > filename.out

How do I take my output file from above, and change the user and group ownership to root:sys?
0
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

woolmilkporcCommented:
Quite easyly. You don't need the output file, we can do it in one go.

This is a version which will just show the commands but  not actually excute them:

find /start/dir \( -type f -o -type d \) -a \( -user adm4 -o -group adm4grp \)  |\
 xargs -I{} echo chown root:sys "{}"

If you're satisfied with the outcome run the real thing:

find /start/dir \( -type f -o -type d \) -a \( -user adm4 -o -group adm4grp \)  |\
 xargs -I{} chown root:sys "{}"

Please note the quotes around "{}"! They're important to take filenames containing spaces into account. The "find" implementation of AIX does not have the "-print0" action.

wmp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AIX25Author Commented:
There are times where are run the find command like this "find . \( -type f -o -type d \) -a \( -user adm4 -o -group adm4grp \) -ls". Where I sue the "." to start the find in my current pwd. The issue is that I run in directories that have symbolic links. Is there a way to make the find command follow symbolic links? There are rougly 25 sub-dirs with symlinks and it would be very inefficient to run the find the command on every physical path than running it again the current pwd and follow symbolic link. Do you know of a way?
0
woolmilkporcCommented:
Yes. Use the "-L" flag. It causes  the file information and file type evaluated for each symbolic link to be those of the file/directory referenced by the link, and not the link itself.

find -L  . \( -type f -o -type d \) -a \( -user adm4 -o -group adm4grp \) -ls
0
AIX25Author Commented:
One last item on this question. How do I exclude all .snap files from the find command in your above syntax?
0
woolmilkporcCommented:
Here you go!

find -L  . ! -name "*.snap"  \( -type f -o -type d \) -a \( -user adm4 -o -group adm4grp \) -ls
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.