Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In this case, why 1 byte extra when computing the file size? [closed]

I made this following observations after making a text file on Ubuntu 12.10 through GUI (alt+enter) as well as in Terminal (ls -l).

  • when file was empty : file size = 0 byte.
  • when one character : file size = 2 bytes.
  • when two characters : file size = 3 bytes.

Why 1 byte extra when the file just contains one character, i know this is not because of End-Of-File because when i wrote a c program the loop terminated when it reached End-Of-File and it gave me the same results, so obviously this doesn't count, then what is it?

But on windows when the file contained one character the file size was just 1 byte, it was normal. What are the things behind all this stuffs?

like image 513
dimSutar Avatar asked Dec 05 '12 06:12

dimSutar


People also ask

Why do file sizes change?

Because of the way file systems organize and track your data on disk, size may be displayed differently in one place than in another. When backing up online, my pictures only take up ~65 GB, but ~88 GB are reported on my computer.

Why do some file types take up more memory than other file types?

PSD and RAW take up so much space on devices mostly because people collect so many photos. High-quality photo files take up the most space on your device. The more dots per inch (DPI) — an indicator of photo clarity — in a photo, the more space it takes up.

How can a file be 0 bytes?

Zero-byte files can occur when file transfers do not complete successfully. This may happen when a file is incompletely downloaded via the Web or an FTP (file transfer protocol) client, or when an email attachment is not transmitted correctly. The result may be a file that has a name, but no data.

Why are two identical files different sizes?

If they have a different size, then they definitely have different contents. A file is (pretty much) just a sequence of bytes - and if two sequences have different lengths, they're different sequences.


1 Answers

It's due to text editor you are getting this. YOu must have pressed extra terminating character such as newline.

If you want 1 byte size for 1 character in a file.

Just do like this on you terminal.

#cat > file // create a file for input
x{CTRL+D}  // after inputting one character 'x' , press CTRL+D twice
           // one for terminating file and one for killing the cat process.

#ls -l  // list the file

You will get exactly 1 byte file size.

Try it. (It's working on my system Ubuntu 11.04)

like image 93
Omkant Avatar answered Oct 18 '22 19:10

Omkant