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
Guthrie
  • 13
  • 3

1 Answers1

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
pLumo
  • 22,231
  • 2
  • 41
  • 66
  • 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 07 '19 at 08:46
  • add `-name "*.txt"` to the `find` command. – pLumo Nov 07 '19 at 09:22
  • last question, if numfmt isnt available, is there an alternative? – Guthrie Nov 08 '19 at 01:02
  • see [here](https://unix.stackexchange.com/a/259254/236063), also read the other answers. – pLumo Nov 08 '19 at 06:52