0

How to list all users and their total consumed space in multiple drives and just for a specific file extension? Basically similar to the output below:

User1 15T /datadrive01
User2 10T /datadrive01
User3 11gb /datadrive01

User1 20T /datadrive02
User2 10gb /datadrive02
User3 5gb /datadrive02
0

This will take a while:

for mnt in /datadrive01 /datadrive02; do
    find "$mnt" -printf '%u %k\n' 2>/dev/null \
      | awk -v "mnt=$mnt" '{sum[$1]+=$2} END {for (u in sum) print u,sum[u],mnt}' \
      | numfmt --from-unit=1000 --to=iec --field=2
    echo
done
  • find all files and print user and disk usage of size (-printf '%u %k\n')
  • with awk sum up all sizes per user and print.
  • with numfmt optionally convert sizes to human-readable format
  • echo just for the blank line in between
  • Sorry I am new to this and thanks for the script, it is working. However, where do I specify that the files I want to be searched are only those with a file extension of say, '.txt'? – Guthrie Nov 7 at 8:46
  • add -name "*.txt" to the find command. – pLumo Nov 7 at 9:22
  • last question, if numfmt isnt available, is there an alternative? – Guthrie Nov 8 at 1:02
  • see here, also read the other answers. – pLumo Nov 8 at 6:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.