Find the answer to your Linux question:
Results 1 to 4 of 4
Hi, I have a dir with loads of files and sub-directories, owned by different users and I wanted to generate a list of the summarized file-sizes by owner. I tried ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2007
    Posts
    3

    view disc-usage by owner


    Hi,

    I have a dir with loads of files and sub-directories, owned by different users and
    I wanted to generate a list of the summarized file-sizes by owner.

    I tried something like:

    find . -print0 -type f -user someuser > tmp
    du -sh --files0-from=tmp

    but I get just a bunch of crap.

    How can I do this?

  2. #2
    Linux Engineer hazel's Avatar
    Join Date
    May 2004
    Location
    Harrow, UK
    Posts
    1,167
    I'd use a combination of ls -l and awk. For example
    Code:
     ls -l directory|awk '$3~name{total=total+$5};END {print total}'
    will print out the total disk space for files owned by name in directory. You can tweak the program so that it prints out the data you want.
    "I'm just a little old lady; don't try to dazzle me with jargon!"

  3. #3
    Just Joined!
    Join Date
    Oct 2007
    Posts
    3
    Works perfectly, thanks!

    tweaked it to something like:

    Code:
    ls -lR /somedir/ | awk '$3~"user1"{total1=total1+$5} $3~"user2"{total2=total2+$5};END {print "user1: " total1 "\nuser2: " total2 }'

  4. #4
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    Wrap your command in a for loop and cater for all names present:
    Code:
    for name in $(ls -l /somedir | awk '{print $3}' | sort -u)
    do
        echo $name   # (your counting command here)
    done

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •