You are not logged in.
Hello,
Here is what I need, hope someone can help me:
I want to get a sum of all file sizes in a current directory, based on the file extensions, e.g.
250K *.txt
800K *.php
2M *.jpg
10M *.mp4
I was trying something with "du -sch" and "type -f" but couldn't get a good result...
Thanks!
Offline
I seem to remember finding a util that did just this... stay tuned, if I find it, I will post back.
CPU-optimized Linux-ck packages @ Repo-ck • AUR packages • Zsh and other configs
Offline
Offline
If graysky doesn't find a tool, you could always do this in bash/zsh.
Step 1) Iterate through all files in whatever directory
for i in *; do
Step 2) Add the file size of each file to an associative array with the file extensions as the keys
((array[${i##*.}]+=$(du $i | cut -f 1)))
Step 3) Print your array and do whatever unit conversions necessary
Step 4) Profit
Offline
Still not quite there, but here is what I came up with using bits from here and there:
#!/bin/bash
ftypes=$(find . -type f | grep -E ".*\.[a-zA-Z0-9]*$" | sed -e 's/.*\(\.[a-zA-Z0-9]*\)$/\1/' | sort | uniq)
for ft in $ftypes
do
echo -n "$ft "
find . -name "*${ft}" -exec du -shc {} + | tail -1 | awk '{print $1}'
done
The output is:
.abc 3M
.bgh 150K
.cig 100M
.de 80K
...
but I can't the output as it as described in OP...
Offline