Finding the file size
Hi,
I'm asked to make a shell script that stores the total filesize of all the files in a given directory into a variable. Does any one have any clue on how to do this? regards |
Is a teacher asking? If so - keep searching :}
Cheers, Tink |
not really. How do find the file size for a file only? like var=`filesize yyy.exe` or some thing like that
|
ls -l filename|awk '{print $5}'
or du -sb filename Cheers, Tink |
ah, that's pretty short. I actually used ls -l for each file, then use a for loop to print out the 5th line. The concept is the same, but the awk method is obviously a lot shorter!
thanks |
Welcome!
The advantage of the awk method is that it's next to trivial to calculate the size of all the files. Code:
find -ls | awk '$11 != "." {total+=$7;printf("%12d\t", $7);for(i=11;i<=NF;i++){printf("%s", $i)}printf("\n")}END{print "Total: ", total}' Cheers, Tink |
thanks Tinkster. that's what I need.
|
good stuffs
|
Yet another way:
Code:
stat -c %s file.txt |
All times are GMT -5. The time now is 02:38 AM. |