The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Find Files in a Directory Excluding Subdirectories Amol_Dicholkar UNIX for Dummies Questions & Answers 2 12-11-2008 07:54 AM
How to remove directory with subdirectories and files? ppa108 UNIX for Dummies Questions & Answers 9 11-25-2008 02:02 AM
search files in a directory and its subdirectories Net-Man Shell Programming and Scripting 1 09-04-2008 09:25 PM
Shell:Find a word in files in a directory and subdirectories yeclota Shell Programming and Scripting 4 08-29-2008 05:05 AM
Find all files created by a specified user in a directory and its subdirectories abhilashnair UNIX for Dummies Questions & Answers 5 06-13-2007 02:37 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-27-2009
vyasa vyasa is offline
Registered User
  
 

Join Date: May 2009
Posts: 6
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 (permalink)  
Old 05-27-2009
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,643
Code:
find somedirectory ! -user root -exec ls -l {} \; | awk '{print $2}' | sort -u
  #3 (permalink)  
Old 05-27-2009
amitranjansahu's Avatar
amitranjansahu amitranjansahu is offline
Registered User
  
 

Join Date: Jan 2009
Location: Gurgaon,INDIA
Posts: 239
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 (permalink)  
Old 05-27-2009
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,422
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 (permalink)  
Old 05-27-2009
devtakh devtakh is offline
Registered User
  
 

Join Date: Oct 2007
Location: Bangalore
Posts: 514
Code:
find directory/ -type f ! -user 0 -exec ls -l {} \;

-Devaraj Takhellambam
  #6 (permalink)  
Old 05-27-2009
vyasa vyasa is offline
Registered User
  
 

Join Date: May 2009
Posts: 6
Thanks for the reply...is there a way to implement this using PERL scripting.
  #7 (permalink)  
Old 05-27-2009
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,422
Quote:
Originally Posted by vyasa View Post
Thanks for the reply...is there a way to implement this using PERL scripting.
yes. File::Find
Sponsored Links
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 06:27 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0