Search code examples
shellawkfindcsh

Print file count owned by a given user


How to print the number of files owned by every user in a given directory? So far I am printing user name and disk size. However I want to report out the output of "find $dirname -user <user_name>| wc -l" and print that as a third field in the below printf

set dirname = "a/b/c"

    find $dirname -printf "%u %s\n" 

Solution

  • I have a feeling you want to do something like this :

    find $dirname -printf "%u %s\n" \
     | awk '{s[$1]+=$2;c[$1]++}END{for(u in s) print u,s[u],c[u]}
    

    This will print a list of users with total accumulated file-size and the total amount of files.