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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting to parse a directory and its subdirectories and find owner name of files
# 1  
Old 05-27-2009
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
# 2  
Old 05-27-2009
Code:
find somedirectory ! -user root -exec ls -l {} \; | awk '{print $2}' | sort -u

# 3  
Old 05-27-2009
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/'
# 4  
Old 05-27-2009
if you have Python
Code:
#!/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

# 5  
Old 05-27-2009
Code:
find directory/ -type f ! -user 0 -exec ls -l {} \;


-Devaraj Takhellambam
# 6  
Old 05-27-2009
Thanks for the reply...is there a way to implement this using PERL scripting.
# 7  
Old 05-27-2009
Quote:
Originally Posted by vyasa
Thanks for the reply...is there a way to implement this using PERL scripting.
yes. File::Find
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

How to set owner and permission for files/directory in directory in this case?

Hi. My example: I have a filesystem /log. Everyday, log files are copied to /log. I'd like to set owner and permission for files and directories in /log like that chown -R log_adm /log/* chmod -R 544 /log/*It's OK, but just at that time. When a new log file or new directory is created in /log,... (8 Replies)
Discussion started by: bobochacha29
8 Replies

2. Shell Programming and Scripting

Append string to all the files inside a directory excluding subdirectories and .zip files

Hii, Could someone help me to append string to the starting of all the filenames inside a directory but it should exclude .zip files and subdirectories. Eg. file1: test1.log file2: test2.log file3 test.zip After running the script file1: string_test1.log file2: string_test2.log file3:... (4 Replies)
Discussion started by: Ravi Kishore
4 Replies

3. Shell Programming and Scripting

Find/searching files in subdirectories excluding the fiels in Parent Directory

Hi All, requirement is to find and remove the files from sub directories but it should exclude the files from parent directory. At present i am using the below one but it finds and remove files from both parent and sub directories. find ${PATH} -type f \( -name securitas\* -o -name \*gz... (1 Reply)
Discussion started by: Naveenkk
1 Replies

4. Shell Programming and Scripting

Find command to search files in a directory excluding subdirectories

Hi Forum, I am using the below command to find files older than x days in a directory excluding subdirectories. From the previous forums I got to know that prune command helps us not to descend in subdirectories. Though I am using it here, not getting the desired result. cd $dir... (8 Replies)
Discussion started by: jhilmil
8 Replies

5. Shell Programming and Scripting

Find files only in current directory...not subdirectories

Hi, I have to find files only in the current directory...not in the sub directories. But when I use Find command ... it searches all the files in the current directory as well as in the subdirectories. I am using AIX-UNIX machine.Please help..I tried to use maxdepth..but it is not working in AIX. (2 Replies)
Discussion started by: vsachan
2 Replies

6. UNIX for Dummies Questions & Answers

Group files by owner and show directory

Hello, i would like to find huge files and group them by owners. To find big files i use this command: ls -lR | sort -bnr +4 | head -n 75 which give me 75 biggest files, then i need to see in which subdirectory is every file. second thing i dont know is how to group those files by owner, could... (6 Replies)
Discussion started by: dealer1985
6 Replies

7. Shell Programming and Scripting

Find directory name while traversing subdirectories

Hi, I have a parent directory in which I have sub directories of different depth /usr/usr1/user2/671 /usr/usr1/672 /usr/user2/user1/673 /usr/user2/user3/user4/674 And I need the names of all the directories that which starts only with 6 in a file. Thanks, (12 Replies)
Discussion started by: arun_maffy
12 Replies

8. UNIX for Dummies Questions & Answers

Find Files in a Directory Excluding Subdirectories

Hi, I have a filename Location.txt in a directory /abc. Similar name file is present in its subdirectory /abc/xyz. I want to find the file which is present only in /abc and not in /abc/xyz. Please any1 of u can provide a quick suggestion. Its very urgent. Thanks, Amol (2 Replies)
Discussion started by: Amol_Dicholkar
2 Replies

9. Shell Programming and Scripting

Shell:Find a word in files in a directory and subdirectories

I'm looking to write a ksh code with will be alble to find a word like 'toto' in all files going from my current directory. eg. /doc ----------->have: text.c which "toto" /doc/usr-------->have: build.pc, help.java which "toto" /doc/usr/cach -->have: test.sh which "toto" /doc/build... (4 Replies)
Discussion started by: yeclota
4 Replies

10. UNIX for Dummies Questions & Answers

Find all files created by a specified user in a directory and its subdirectories

Is there a command or shell script which can be used for Finding all files created by a specified userid in a directory and its subdirectories. Say, I want to find all such files in directory /abc as well as in all the subdirectories such as /abc/xyz or /abc/xyz/pqr aqnd so on which was created... (5 Replies)
Discussion started by: abhilashnair
5 Replies
Login or Register to Ask a Question