Imi cer suze pt. problemele avute cu e-mailurile trimise anterior.
Banuiesc ca subiectul e 'expirat' .... totusi mailul trimis era (=20
sperand sa il mai ajute cu ceva pe cel care a intrebat ):
Solutii ar mai fi : ls -lt *.jpg | awk '{x +=3D $5}END{print "Tot size: =
", x}'
Daca se doreste doar scripting , intradevar solutia=20
echo $(find . -type f -name ".*jpg" -printf "%s+")0 | bc
este cea mai rapida. Dar pt. numar mare de fisiere, poate ar fi bine sa =
scrii 10 randuri in C. Nu se compara din punct de vedere al vitezei.
[EMAIL PROTECTED]:~/testsize/testfiles> ls -lt *.lic | wc -l
4207
[EMAIL PROTECTED]:~/testsize/testfiles> time ./msize
Tot. size =3D 8313713 bytes
real 0m0.015s
user 0m0.000s
sys 0m0.020s
[EMAIL PROTECTED]:~/testsize/testfiles> time ls -lt *.lic | awk '{x +=3D =
$5}END{print "Tot size: ", x}'
Tot size: 8313713
real 0m0.068s
user 0m0.060s
sys 0m0.020s
[EMAIL PROTECTED]:~/testsize/testfiles> time echo $(find . -type f -name =
"*.lic" -printf "%s+")0 | bc
8313713
real 0m0.042s
user 0m0.010s
sys 0m0.020s
[EMAIL PROTECTED]:~/testsize/testfiles>
Functia in C care vine utilizata :
int getSize(char* root, char* ptn)
{
DIR *dp;
struct dirent* den;
struct stat fstat;
int rsize=3D0,dsize=3D0;
dp=3Dopendir(root);
if (dp !=3DNULL) {
while ( den =3D readdir(dp) ) {
stat ( den->d_name,&fstat);
if ( S_ISDIR (fstat.st_mode) && !strstr(den->d_name,".") =
) rsize +=3D getSize(den->d_name,ptn);
else if ( !fnmatch(ptn,den->d_name,FNM_PATHNAME) ) rsize =
+=3D fstat.st_size; }
closedir (dp) ;
return rsize;
}
else return 0;
}
Mihai Maties wrote:
>On Thursday 27 May 2004 19:33, Adrian Popescu wrote:
> =20
>
>>On Thursday 27 May 2004 17:45, Dan Uscatu wrote:
>> =20
>>
>>>problema: sa se calculeze suma dimensiunilor tuturor fisierelor de un
>>>anumit tip (de exemplu .jpg) din directorul curent.
>>> =20
>>>
>>stat -c %s *.jpg | awk '{x=3Dx+$1} END {print x}'
>> =20
>>
>
>Orice solutie bazata pe faptul ca te astepti ca bash-ul sa-ti faca =
"expand" la=20
>* din linia de comanda are un mare inconvenient: daca ai multe fisiere =
atunci=20
>primesti un foarte frumos: "argument list too long".
>
>Bottom line(s):
>- solutia de mai sus e ok, in cazul in care ai putine fisiere (cu nume =
nu=20
>foarte lungi)
>- daca ai in vedere ca fisierele ar putea fi si in subdirectoare, =
gasirea=20
>lungimii lor este recomandat a fi facuta cu find
>- parsarea output-ului lui "ls-lR" e iarasi destul de consumatoare de =
timp in=20
>cazul unui numar mare de fisiere
>
>Deci solutia optima ar fi:
>
>echo $(find . -type f -name ".*jpg" -printf "%s+")0 | bc
>
>
>Mihai
>
>---=20
>Detalii despre listele noastre de mail: http://www.lug.ro/
>
>
>
> =20
>
Gruppo Telecom Italia - Direzione e coordinamento di Telecom Italia =
S.p.A.
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
CONFIDENTIALITY NOTICE
This message and its attachments are addressed solely to the persons
above and may contain confidential information. If you have received
the message in error, be informed that any use of the content hereof
is prohibited. Please return it immediately to the sender and delete
the message. Should you have any questions, please send an e_mail to=20
[EMAIL PROTECTED] Thank you
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
---
Detalii despre listele noastre de mail: http://www.lug.ro/