Operating System - HP-UX
1825803 Members
2457 Online
109687 Solutions
New Discussion

Re: Counting file sizes ???

 
SOLVED
Go to solution
someone_4
Honored Contributor

Counting file sizes ???

I did an ll looking for the bigest files and I found one that is 2147483647. Now the way I read it this is 1000000000=1000megs so this would be like a file a little bigger then 2 gigs ? Am I right or an I counting wrong?
And is there a way I can run the ll command to come out with megs as output ?

Richard
7 REPLIES 7
Sridhar Bhaskarla
Honored Contributor
Solution

Re: Counting file sizes ???

Richard,

Do a du -sk on the file. YOu will get the size in KB and it will be easier for you.

For ex., du -sk file

2046123 file

This means it is of 2 GB.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
linuxfan
Honored Contributor

Re: Counting file sizes ???

Hi Richard,

you could do something like
du -kx * |sort -n
The last file/directory would be the biggest size in KB.

If you only want the biggest size in files (in KB)then

ls -al | grep '^-' | sort +4 |tail -1 | awk '{print $5, $9}'

-HTH
Ramesh
They think they know but don't. At least I know I don't know - Socrates
linuxfan
Honored Contributor

Re: Counting file sizes ???

Hi Richard,

If you want the size in MB

ls -al | grep '^-' | sort +4 |tail -1 | awk '{print $5/1048576, $9}'

Ofcourse you do lots of formating, and this is not the only way to do it.

-Regards
Ramesh
They think they know but don't. At least I know I don't know - Socrates
Patrick Wallek
Honored Contributor

Re: Counting file sizes ???

2,147,483,647 bytes / 1024 =
2,097,151.999 KB / 1024 =
2,047.999 MB / 1024 =
1.999 GB

So this file is essentially a 2 GB file. You are reading the number and doing the math correctly.

As far as I know there is no option to tell 'll' to put output in MB directly. You have been given some other good ideas though.

By the way, if the file hit this size and didn't grow any more, I would guess that do not have the 'large files' option turned on for this LV.

You can use fsadm to check and to turn on largefiles if you wish. Do a 'man fsadm' for more info.
Satish Y
Trusted Contributor

Re: Counting file sizes ???

Hi Richard,

What Pat says is correct, and 1KB = 1024Bytes(not 1000Bytes) so 1GB = 1073741824 Bytes..... and there is no option for ll cmd to tell u size in MB.

Cheers...
Satish.
Difference between good and the best is only a little effort
Magdi KAMAL
Respected Contributor

Re: Counting file sizes ???

Hi Richard,

You are right, it's a 2 gigs file.

To calculate directory size in kilobytes :
#du -sk /dir

To calculate size of selective files inkilobytes :

a=`ls -al *.log ? awk '{print $5}'`
result=0
for c in $a
do
result=`expr $result + $c`
done

sizeInKilo=`expr $result \/ 1024`
sizeInMega=`expr $sizeInKilo \/ 1024`
sizeInGiga=`expr $sizeInMega \/ 1024`

echo "Size in KB = $sizeInKilo"
echo "Size in MB = $sizeInMega"
echo "Size in GB = $sizeInGiga"


Magdi

Magdi KAMAL
Respected Contributor

Re: Counting file sizes ???

Hi again ,

in the expr command, you may see a strange signe some how like a V, but it is not :

It is a back slash followed immediately by slash.

Magdi