Reputation: 3919
Suppose directory structure on Ubuntu is /home/f1/a
, /home/f2/a
, /home/f3/a
and /home/f4/a
. Suppose my objective is to know the disk size of folders a
within each f1
,f2
,f3
,f4
(not the size of files inside these folders but the folders themselves); and to do it while I'm in /home
.
Question What's the shell command I can run from /home
to get the disk size of each folder a
?
In my real world example I have 60 of these directories (i.e. ~/f1/a
,~/f2/a
,...,~/f60/a
) so a command that doesn't spam too much other information is preferred.
Upvotes: 0
Views: 543
Reputation: 1594
this code works :
for i in `seq 1 60`
do
du -ch ~/f$i/a | tail -n 1 | awk -F' ' {'print $1'}
done
Upvotes: 1
Reputation: 3175
The below will give you a break down of the folder sizes and a total at the end for all the folders no matter how many there are as long as they start with f and are in /home
du -ch /home/f*/a/
Output:
24K /home/mgreen/f11/a/
4.0K /home/mgreen/f12/a/
4.0K /home/mgreen/f61/a/
32K total
I think you are looking for something more like the following though which will let u grab a total for each /a/ folder and not the total of all of them.
for i in $(ls /home/mgreen |grep 'f[0-9]');do for d in $(ls /home/mgreen/$i|grep "a");do printf "$i$d " ;du -sch /home/mgreen/$i/$d | tail -n 1 | awk '{print $1}';done ;done
where $i equals the top level directory f1-100 and $d equals the 'a' directory. The extra loops keeps $a assigned to a variable for printing.
Output:
f11/a/ 24K
f12/a/ 4.0K
f61/a/ 4.0K
Hope this helps.
Upvotes: 2