Computing.Net > Forums > Unix > Size of files

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Size of files

Reply to Message Icon

Name: nauj
Date: February 14, 2007 at 01:15:00 Pacific
OS: AIX5.1
CPU/Ram: IBM
Product: IBM
Comment:

Hi,

I want to know the size of a group of files.
Files with some conditions.
For example, files which name start with VAL.
ls -la VAL*
VAL200601
VAL200602
VAL200603
¿can I obtain the sum of the sizes of these files?.

Thanks in advance.



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: February 14, 2007 at 07:00:17 Pacific
Reply:

Of course, ls doesn't differentiate between a file and a directory. Just add up the 5th field of ls:

#!/bin/ksh

tsize=0
ls -la VA*|while read f1 f2 f3 f4 fsize f7
do
tsize=$((tsize+fsize))
done

echo $tsize


0

Response Number 2
Name: Vertabreaker
Date: February 28, 2007 at 12:03:08 Pacific
Reply:

If these files are all within the same directory and you just want to get a quick sum without using a script, you can use du.

Example:

du -ks //displays file size sum in kilobytes
du -ms //same as above but in megabytes
du -gs //same but in gigs

If there's other files in the directory you don't need to know the size of, then I would go with a script like the one Nails provided.

Hope this helps.

~Verta


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Size of files

how to identify the size of a file www.computing.net/answers/unix/how-to-identify-the-size-of-a-file-/7523.html

Adding file size & output to file www.computing.net/answers/unix/adding-file-size-amp-output-to-file/7330.html

how to delete last 3 lines of files www.computing.net/answers/unix/how-to-delete-last-3-lines-of-files/6466.html