to parse a directory and its subdirectories and find owner name of files

hi all,

i need to capture all the files in a directory and its subdirectories that have owner name different than the root owner.

for one file it is " stat -c %U filename " but i need to search for each and every file and record it.

thanks in advance

find somedirectory ! -user root -exec ls -l {} \; | awk '{print $2}' | sort -u

Here is the code it will print the files that is not owned by root

==============

find $PATH -type f -exec ls -l "{}" ";" |
awk -F" " '{print $3 ,$9}' |
awk ' $1 !~ /root/'

if you have Python

#!/usr/bin/env python
import os,stat
for r,d,f in os.walk(os.path.join("/home","path","path2") ):
    for files in f:
        filepath=os.path.join(r,files)
        owner=os.stat(filepath)[stat.ST_UID]
        if owner!=0:
            print filepath
find directory/ -type f ! -user 0 -exec ls -l {} \;

-Devaraj Takhellambam

Thanks for the reply...is there a way to implement this using PERL scripting.

yes. File::Find

above commands showing error when run with back quotes in perl script

You will have to use escape characters to use them

hi dinjo,

can you please be more specific as to how to use escape sequences to make this command work in perl

Just a example.See the backslash

/usr/bin/awk \'{ if (\$1 > 85) {print \$1 \$4\ } } \' | grep -v \"Name\"

What command are you trying to run?

i am trying to run the below command in the perl script

system(" find . ! -user username -exec ls -l {} \; | awk \'{print $3,$9}\' ");

actually i am facing problem in using the escape characters in the above command.

don't need to use the system find command. you can use Perl's module File::Find.

yes use the File::Find module
anyway, that's the way you can get your above command to work without great masking:

$a='find . ! -user 0 -exec ls -l {} \; | awk \'{print $3,$9}\'';
system ("$a");

the only thing you have to mask are single quotes

if you wan't to use a variable out of the perl script, use a="command" ; and just mask the \" in your command