views:

64

answers:

2

I have a folder containing .tcb and .tch files. I need to know what the size of all .tcb files together, respectively of all .tch files is. I did like this:

1) I created a temp folder and then:

mv *tch temp

2) and then:

du -sk temp

I found the command in the Internet and wikipedia says this: "du (abbreviated from disk usage) is a standard Unix program used to estimate the file space usage". I think the reason why it says that it is an estimation is that if there are links then the size of the link will be shown instead of the linked file.

But if I do

ls -l

in the temp folder (which contains the all *.tch) files and then sum up the sizes which are displayed in the terminal, I have another file size. Why is that the case?

Well in sum, what I need is a command which shows me the real file size of *all .tch files in a folder, which can contain also other file types.

I hope anyone can help me with that. Thanks a lot!

+1  A: 

Look at the specific man page for your version of du as they vary considerably in how they count.

"Approximate" can be because:

  1. Blocks used or Bytes used can be reported with Blocks over-stating file sizes that aren't exact multiples of the block size but more accurately represents "space used that I can't use for other stuffs"
  2. Unix files can have "holes" created by seeking a long way and writing. The OS doesn't actually allocate space for the skipped holes.
  3. Symbolic links may or may not be dereferenced to the real file they point to.

If you just want the bytecount use wc -c *.tcb

msw
+1  A: 

You can use the -L option to du if you want to follow symbolic links (that is, calculate the size of the link target, not of the link itself). You can also use the -c option to display a grand total at the end.

Armed with those options, try du -skLc *.tch.

For more details on du, see this manpage.

bta
Note that this might not give you the result you expect if the folder contains a link to a .tch file in the same directory. That file would be counted twice: once for the "actual" file and once for the linked version.
bta
the folder doesn't contain any links so this solution seems to do what I want. thx bta
mkn