Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UNIX: Find size for a list of files

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I am trying to get the total size of list of files in a directory.

We are trying to get the growth rate of a directory in terms of size. Specifically <Wild> Charactered files.

I use du -sk to find the size. But I am a bit confused about, how to get the total size of files like say COM_ABC_?_20010101.* in a directory.

Files in a directory

COM_ABC_1_20010101.txt
COM_ABC_2_20010101.txt
COM_ABC_3_20010101.txt
COM_ABC_4_20010101.txt
COM_ABC_5_20010101.txt
COM_123_1_20010101.txt
COM_XYZ_1_20010101.lst
...

I want the total size of the COM_ABC_?_20010101.* files from the current directory.

I have written a shell to do this, but the total is incremental.

Is there any ready-to-use script for this ?

Thanks in advance.
UKID



 
Hi UKID,

You can use awk for this purpose. eg

$cd <your dir>
$ls -l | awk '/COM_ABC_/ && /_20010101/ {sum+=$5} END{print sum}'
xxxxxx -> The sum of all files whose name matches the criteria '/COM_ABC_/ && /_20010101/'

You can build on the string matching part (ie /COM_ABC_/ && /_20010101/ ) to suit your need.
Hope this helps you.

Rgds,
-Vikram Kalsi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top