Find the answer to your Linux question:
Results 1 to 4 of 4
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    view disc-usage by owner


    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
    Harrow, UK
    I'd use a combination of ls -l and awk. For example
     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
    Works perfectly, thanks!

    tweaked it to something like:

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

  4. $spacer_open
  5. #4
    Wrap your command in a for loop and cater for all names present:
    for name in $(ls -l /somedir | awk '{print $3}' | sort -u)
        echo $name   # (your counting command here)

Posting Permissions

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