LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-22-2011, 05:07 AM   #1
rajsp217
LQ Newbie
 
Registered: Jun 2011
Posts: 12

Rep: Reputation: Disabled
Post how to find total size of all files whose names starting with a*


how to find total size of all files whose names starting with a*

OS: SunOS

du -h a* is giving individual file sizes.


Thanks,
Raj
 
Old 07-22-2011, 06:21 AM   #2
radoulov
Member
 
Registered: Apr 2007
Location: Milano, Italia/Варна, България
Distribution: Ubuntu, Open SUSE
Posts: 212

Rep: Reputation: 36
Code:
perl -le'
 $s += -s for glob shift;
 printf "%f MB\n", $s/1024/1024;
  ' 'a*'
 
Old 07-22-2011, 06:48 AM   #3
rajsp217
LQ Newbie
 
Registered: Jun 2011
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by radoulov View Post
Code:
perl -le'
 $s += -s for glob shift;
 printf "%f MB\n", $s/1024/1024;
  ' 'a*'

Thanks Radoulov.
 
Old 07-22-2011, 07:45 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958
How about simply reading the du man page?
Code:
du -h -c a*
Pipe it through tail or grep or something to extract only the last line if you don't want the rest.

(Edit: D'oh! Just noticed the note about using SunOS. Please ignore this if your version of du doesn't have that option. )

So here's an awk solution instead:
Code:
du -hb a* | awk '{ total+=$1 } END{ print total/1024"k" }'

Last edited by David the H.; 07-22-2011 at 07:55 AM.
 
Old 07-22-2011, 07:47 AM   #5
radoulov
Member
 
Registered: Apr 2007
Location: Milano, Italia/Варна, България
Distribution: Ubuntu, Open SUSE
Posts: 212

Rep: Reputation: 36
Quote:
Originally Posted by David the H. View Post
How about simply reading the du man page?
Code:
du -h -c a*
[...]
The OP is using Solaris ...
 
Old 07-22-2011, 08:52 AM   #6
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958
Quote:
Originally Posted by radoulov View Post
The OP is using Solaris ...
Yes, I know that now. ...Did you not read the edited part of my post?

Notice also that the OP posted this in "Linux Newbie" instead of "Other *NIX" like he should have.

Last edited by David the H.; 07-22-2011 at 08:56 AM.
 
1 members found this post helpful.
Old 07-22-2011, 09:01 AM   #7
radoulov
Member
 
Registered: Apr 2007
Location: Milano, Italia/Варна, България
Distribution: Ubuntu, Open SUSE
Posts: 212

Rep: Reputation: 36
Quote:
Originally Posted by David the H. View Post
Yes, I know that now. ...Did you not read the edited part of my post?
No, I suppose the correction was added after my second post ...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to find grand total size of all files in a directory fakhrul Red Hat 4 04-17-2010 12:28 AM
Total particular files size in a directory kirukan Linux - Newbie 3 01-03-2010 02:48 PM
Knowing total files size from find result, how ??? b-RAM Linux - General 3 12-27-2009 11:59 PM
find *.jpg total size? yanik Linux - General 9 03-22-2006 05:10 AM
Command to find total file size satimis Linux - Newbie 1 01-22-2004 11:19 AM


All times are GMT -5. The time now is 06:15 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration