Not really an answer to your question, I know, but what would such a number mean ? What use do you have for it ?
On Mon, Mar 04, 2013 at 12:01:25AM +0800, f5b wrote: | for example | | 1. | there is only two file in /home/test/ | # ls -l /home/test/ | total 8 | -rw-r--r-- 1 root wheel 2 Mar 3 23:29 a.txt | -rw-r--r-- 1 root wheel 3 Mar 3 23:29 b.txt | | So the total size of all files ( a.txt + b.txt ) should be 5 Bytes. | How to get total size ( 5 Bytes ) directly but not the 8 Bytes. a.txt is 2 bytes long, but occupies the minimum allocation unit of your filesystem (2 kilobytes, in your case). The "total 8" is a reference to the total number of sectors (512 bytes low level disk allocation units) in use (2 files of 2 kilobytes use 4 kilobytes in total and 4 kilobytes of storage require 8 physical disk sectors). | 2. | # man du | says, | -h "Human-readable" output. Use unit suffixes: Byte, Kilobyte, | Megabyte, Gigabyte, Terabyte, Petabyte, Exabyte in order to | reduce the number of digits to four or less. | | but | # du -h /home/test | 6.0K /home/test | | How to let unit suffixes: Byte display (come out) but not Kilobyte? Note that du is reporting the correct size. 2K for a.txt, 2K for b.txt and 2K for the directory itself for a total of 6K. If you want du to show you a number in bytes, touch a non-existing file (i.e. create an empty file): [weerd@despair] $ touch /tmp/X [weerd@despair] $ du -sh /tmp/X 0B /tmp/X | just like | # du -b /home/test ( option "-b" not exist) | 5B /home/test /home/test is not 5 bytes. It's way bigger. As an upside, it won't cost you any extra diskspace to grow a.txt with 10 more bytes. Up until 2048 bytes, the space allocated to this file on the filesystem does not change. If you really want to know how many bytes are stored in a set of files you could go [weerd@despair] $ mkdir /tmp/test [weerd@despair] $ cd /tmp/test [weerd@despair] $ echo a > a.txt [weerd@despair] $ echo bb > b.txt [weerd@despair] $ ls -l total 4 -rw-r--r-- 1 weerd wheel 2 Mar 3 21:54 a.txt -rw-r--r-- 1 weerd wheel 3 Mar 3 21:54 b.txt [weerd@despair] $ ls -l /tmp/test/* | awk '{SUM+=$5} END {print SUM}' 5 [weerd@despair] $ cat * | wc -c 5 The first approach iterates over the output of ls(1) and uses awk to sum up the filesizes of all files in the listing. The second solutions simply reads all files and writes them to wc(1) which then shows a count of the number of bytes it read. Note that neither of these solutions take hardlinks into account (or subdirectories, or other fancy stuff). Also note that I have a smaller minimum allocation unit on my /tmp partition, since the two files consume 4 sectors worth of storage together. You may want to read up on filesystem design. Cheers, Pau 'WEiRD' de Weerd -- >++++++++[<++++++++++>-]<+++++++.>+++[<------>-]<.>+++[<+ +++++++++++>-]<.>++[<------------>-]<+.--------------.[-] http://www.weirdnet.nl/