LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to find total size of all files whose names starting with a* (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-find-total-size-of-all-files-whose-names-starting-with-a%2A-893119/)

rajsp217 07-22-2011 05:07 AM

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

radoulov 07-22-2011 06:21 AM

Code:

perl -le'
 $s += -s for glob shift;
 printf "%f MB\n", $s/1024/1024;
  ' 'a*'


rajsp217 07-22-2011 06:48 AM

Quote:

Originally Posted by radoulov (Post 4422196)
Code:

perl -le'
 $s += -s for glob shift;
 printf "%f MB\n", $s/1024/1024;
  ' 'a*'



Thanks Radoulov.

David the H. 07-22-2011 07:45 AM

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" }'

radoulov 07-22-2011 07:47 AM

Quote:

Originally Posted by David the H. (Post 4422246)
How about simply reading the du man page?
Code:

du -h -c a*
[...]

The OP is using Solaris ...

David the H. 07-22-2011 08:52 AM

Quote:

Originally Posted by radoulov (Post 4422248)
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.

radoulov 07-22-2011 09:01 AM

Quote:

Originally Posted by David the H. (Post 4422310)
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 ...


All times are GMT -5. The time now is 01:54 PM.