vyasa
May 27, 2009, 11:03am
1
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
vyasa
May 27, 2009, 2:58pm
6
Thanks for the reply...is there a way to implement this using PERL scripting.
vyasa
May 28, 2009, 2:39am
8
above commands showing error when run with back quotes in perl script
You will have to use escape characters to use them
vyasa
May 28, 2009, 4:36am
10
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?
vyasa
May 29, 2009, 5:21am
13
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