How to find the actual size of a simple text file

How to find the actual size of a simple text file.

I found that size is = size of sum of all ASCII characters. :sarcastic:

But where do the filename, EOF, and start-of-file or file-headers, file-type go?

$ du -hb text.dat
43 text.dat

where 43 bytes is the total number of ASCII characters.

$ wc -m text.dat … ie print the byte counts
43 text.dat

$ wc -c text.dat … ie print the character counts
43 text.dat

$ stat -c%s text.dat … ie where: %s Total size, in bytes
43

$ ls -l text.dat |awk -F " " ‘{ print $5 }’
43

ls -l text.dat | cut -d " " -f 5
43

Al these commands do not show what I want to know.

I dont find any attachment option:

So file is:

rat
he naughty boy
456 wheres 7

here is 7

The file size is 43 bytes. What is wrong with that?

rat
he naughty boy
456 wheres 7

here is 7

Name of the file is not part of the file content. There is no header, EOF character or any other meta-data information stored in the file.

Wow, what a great discovery. :stuck_out_tongue: Actually not even ASCII characters, just octets. There is no distinction between text and binary files in Unix.

But where do the filename, EOF, and start-of-file or file-headers, file-type go?

The filename is stored in the directory. In fact there may not be a unique filename due to hard links.

There is no special EOF character. The OS knows EOF has been reached by the file length. Thus no problems with having to treat such a character specially, which if you think about it, causes headaches with binary files. This may be obvious now, but ancient OSes made the mistake of dedicating a special character or sequence to mean end of file and this complicated a programmer’s life.

There is no “file type”, except for the types of plain file, directory, block device, character device, pipe, other special file, and so forth. This is stored in the file’s metadata, in the inode, as are the file permissions, file size, timestamps, etc. Programs may pay attention to filename suffixes, but this is not an OS issue.

There are no “file headers” so no start of file marker. The start of data is the start of file.

Al these commands do not show what I want to know.

Then you need to learn more about the Unix filesystem, and understand what the OS does and does not do and why Unix has such a clean architecture.

I dont find any attachment option:

Attachments are not an OS issue, just a certain way of bundling content. See the appropriate RFCs for email and HTML multipart files.

Thanks for your reply.