-1

How do I calculate the block-filesize that all the files in a directory take? and how do I calculate the real size of all the files in the directory?

I tried some variations with df/du but they don't seem to work.

1
  • 3
    What's wrong with du -s the-dir? Commented Nov 22, 2016 at 19:37

1 Answer 1

0
ls -sa | awk '{ SUM += $1 } END { print "Block size=" SUM }'

the -s option of ls print the allocated size of each file, in blocks

And the real size :

ls -la | awk '{ SUM += $5 } END { print "Dir size=" SUM }'
1
  • 2
    parsing the output of ls is a greatly inferior method to using du. Parsing ls is generally a bad idea: unix.stackexchange.com/questions/128985/why-not-parse-ls. du is specifically made for getting information about disk space usage/size on disk. Commented Nov 22, 2016 at 19:51

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.