Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I find how much disk does a list of files uses? I'm looking for a variation of

du -s *.sql

I want to see only the grand total, and with the command above, it always shows a line for each file.

share|improve this question
up vote 9 down vote accepted

You can use tail to cut the last line (the total) from the output of du:

du -c *.sql | tail -n 1

There seems to be no way to make du itself report just the total of a set of files.

share|improve this answer

What doesn't work from your example?  Do you want a sum?  man du shows that the -c option provides a sum of usage:

du -sc *.sql

You may also like the -h or -k arguments.

share|improve this answer
    
See my clarification. I want it to print only the sum. – Elazar Leibovich May 23 '11 at 13:41

Your question is very ambiguous but I suspect you are looking for the -c flag to produce a total.

du -c *.sql
share|improve this answer
    
I want it to have the same effect as du -s dir. Which will summarize disk usage of the directory, and nothing else. – Elazar Leibovich May 23 '11 at 13:44

can be a variation like:

du -sch * | grep total
share|improve this answer
    
This doesn't add anything to the accepted answer of du -c * | tail -n 1. Also the -s option doesn't do anything here. – Wildcard Dec 22 '15 at 4:44
1  
This is essentially a combination of the other answers.  The -h option is not called for; the OP didn't ask for it.  | tail -n 1 is better than | grep total because there might be files whose names contain the word total. – G-Man Dec 22 '15 at 4:46
1  
@Wildcard: Actually, -s decreases the amount of data being written through the pipe (if any of the argument(s) are directories). – G-Man Dec 22 '15 at 4:48
    
Aha! @G-Man, good catch; you're right. – Wildcard Dec 22 '15 at 5:31
cat *.sql | wc -c

Answer is in bytes.

share|improve this answer
2  
Yeah, but you need to read the whole whopping 10Gb in order to tell it... – Elazar Leibovich May 26 '11 at 4:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.