How to get size of a list of files with specified extension?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to get size of a list of files with specified extension?
# 1  
Old 10-06-2010
How to get size of a list of files with specified extension?

Command ls -l *cpp lists all cpp program files in a directory. It shows the size of each file. Using a calculator to work out the total size of the cpp files would be very tedious.

Is there a way to get the total size from the command line?
# 2  
Old 10-06-2010
The format of the size field from "ls -l" varies. Please post a sample, blotting anything confidential.
# 3  
Old 10-06-2010
Hi.

Depending on your OS, and if stat is available:

Code:
$ ll
total 8
-rw-r--r-- 1 scott staff  518 Oct  6 13:10 blah.cpp
-rw-r--r-- 1 scott staff 1503 Oct  6 13:10 main.cpp
 
$ stat -c"%s" *.cpp | paste -sd"+" | bc
2021

# 4  
Old 10-06-2010
Quote:
Originally Posted by resander
Command ls -l *cpp lists all cpp program files in a directory. It shows the size of each file. Using a calculator to work out the total size of the cpp files would be very tedious.

Is there a way to get the total size from the command line?

Use the following command
Code:
 
ls -l *cpp|nawk '{sum=sum+$5} END{print sum}'

# 5  
Old 10-06-2010
Code:
$ ruby -e 't=0;Dir["file*"].each{|x| t+=File.size(x)};END{print "total size:#{t}\n"}'

# 6  
Old 10-06-2010
Thank you all.

The total size was 3.2MB. Compressing using 7-zip brings the size down to 0.45MB which is what I will do before backing up the source files to the S3 Amazon cloud store.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Display the .csv extension files based on .done extension fine

Hi All, I want to fetch the files based on .done file and display the .csv files and Wil take .csv files for processing. 1.I need to display the .done files from the directory. 2.next i need to search for the .Csv files based on .done file.then move .csv files for the one directory ... (2 Replies)
Discussion started by: girija.g6
2 Replies

2. Shell Programming and Scripting

List duplicate files based on Name and size

Hello, I have a huge directory (with millions of files) and need to find out duplicates based on BOTH file name and File size. I know fdupes but it calculates MD5 which is very time-consuming and especially it takes forever as I have millions of files. Can anyone please suggest a script or... (7 Replies)
Discussion started by: prvnrk
7 Replies

3. Shell Programming and Scripting

List files with *.i extension in a directory and all its subdirectories + 30days old then remove

I need to write a script to : list files with *.i extension in a directory and all its subdirectories + 30days old, save it in a file and then remove (2 Replies)
Discussion started by: lena keung
2 Replies

4. UNIX for Dummies Questions & Answers

How to list files with no extension together with *.prog files?

Hi, I know that to list files with no extension, we can use.. ls -1 | grep -v "\." And to list .prog files, we can use.. ls -1 *.prog or ls -1 | grep '.prog$' (4 Replies)
Discussion started by: adshocker
4 Replies

5. Shell Programming and Scripting

Compare list [ names and size files ]

Hello, I've downloaded a huge amont of files I've got a list of files from a remote server. -rw-r--r-- 1 str661 strem 453465260 Dec 16 15:54 SATRYS2V1_20021218_temp_bias.nc -rw-r--r-- 1 str661 strem 17669468 Dec 16 18:01 SATRYS2V1_20021225_hdyn_bias.nc -rw-r--r-- 1... (9 Replies)
Discussion started by: Aswex
9 Replies

6. UNIX for Dummies Questions & Answers

How to list files which have same size?

Hi guys, I need to do 100 files comparison after I sorted the files. There are no specific key for sorting so i plan to arrange the files based on the file size. The command that i used to sort the files by size is as per below:- ls -l | sort +4rn | awk '{print $5, $9}' The problem that i... (3 Replies)
Discussion started by: shahril
3 Replies

7. Shell Programming and Scripting

list the files with size in bytes

hi all plz help in listing the files with size in bytes. thnks -Bali (4 Replies)
Discussion started by: balireddy_77
4 Replies

8. UNIX for Dummies Questions & Answers

Files list which are more than 300 MB size

Hi, I need to find files list which are more than 300 MB size? My script It should search all inner directories too. How can I proceed? Any idea? (2 Replies)
Discussion started by: redlotus72
2 Replies

9. UNIX for Advanced & Expert Users

Command to list Files less than or equal to 2k size

Hi, *.xml files stored on date wise folders. I need to extract *.xml files from all the folders. File size is lessthan or equal to 2K. Please let me know command or some shell program to due this job on linux m/c This is urgent, Thanks in advance - Bache Gowda (3 Replies)
Discussion started by: bache_gowda
3 Replies

10. UNIX for Dummies Questions & Answers

How to list files will no extension

Can some one help ...... I want to list files with no extension in directory. I have tried the following ls * That listed all files ls *.* That listed files with extension ls That listed all files Thanks (5 Replies)
Discussion started by: Wing m. Cheng
5 Replies
Login or Register to Ask a Question