7

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.

13

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.

3

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.

  • See my clarification. I want it to print only the sum. – Elazar Leibovich May 23 '11 at 13:41
2

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

du -c *.sql
  • 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
1

can be a variation like:

du -sch * | tail -n 1
  • 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
  • 2
    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
  • that's why i added -s flag ... my understanding of original query is that is wanted the grand total of all files from subdirectories combined in separate grand totals not the listing for every file each how much space eat. If not then -s is wrong will eat all files from subdirectories. Tail -n 1 is ever better, thanks! – totedati Jul 9 '18 at 8:16
-2
cat *.sql | wc -c

Answer is in bytes.

  • 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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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