filesize - windows xp: file size

08
2013-08
  • dotnet-practitioner

    I create a new blank .txt file and file size is 0 bytes.

    Then I just add one character to the file and file size is 1 byte.

    1000 byte file size could mean that it has 1000 characters?

  • Answers
  • kurast

    Depends on the encoding used. If you use ANSI enconding, then yes. It is one byte per char used. If you use UTF-8, for instance , you use more thant 1 byte (more like 3 bytes per character).

  • Otto Allmendinger

    You have to know the difference between file size and disk usage. A file can have little content but use a lot more disk space.

  • Brian Schroth

    I'm not sure what the actual question is here. Do you mean that it's saying it's 1KB (not 1 byte, but 1 kilobyte)? It's probably a case of windows rounding up to the nearest kilobyte. The file is almost certainly only using a byte of disk space, but XP measures file sizes in KB so it rounds up.

    It doesn't round to 0 even though it's far closer to 0 than 1 because 0 implies the file is empty.

  • martinatime

    When a file allocates disk space it does so in chunks based on the configuration used when the disk was formatted. Regardless of the amount of actually data (file size) the chunks need to be allocated to accommodate all of the data. For example using your example: An empty file (zero bytes) requires no chunks to be allocated. As soon as you add a single byte the OS needs to allocate a chunk to accommodate that data. On my XP system that seems to be 4KB. Therefore a file size of 1 byte will take up 4KB of space on the disk. If that chunk is filled to 1 byte over 4KB then another chunk will be allocated to make the size on disk equal to 8KB.

  • xiaolai

    Operating systems (windows, linux etc.) try to divide hard disk volume into pieces (technically called “clusters”), every one of which usually can contain many bytes of data, say 1024 bytes per cluster. Therefore, even if your file contains only 1 byte, the file will still occupy one cluster. If a file contains 1025 bytes, it will occupy two clusters. … and that’s why.


  • Related Question

    filesize - Show file size by type in Linux?
  • gkhewitt

    I'm trying to find out the total size of all files within a directory that have a particular extension.

    I do some offsite backup via rsync but due to limited bandwidth and disk space at the other end I can't do everything, so I'd like to find out, for example, how much disk space MP3 files take up so I can decide whether to remove the mp3 extension from the current list of rsync excluded patterns.

    It's not as simple as doing a 'du -sh' on the My Music directory in there as there's some other file types.

    Thanks!


  • Related Answers
  • John T

    You can use du:

    find Music/ -type f -name "*.mp3" -exec du -shc {} + | tail -1 | awk '{print $1}'

    output example:

    980M
  • pavium

    I just tried the following

    find Music/ -name '*.mp3' -exec ls -l {} \; | awk '{ SUM += $5} END { print SUM/1024/1024 }'
    

    And got the correct answer in Megabytes (1024 x 1024)

  • Jeffrey Vandenborne
    find Music/ -iname "*.mp3" -type f -exec stat -c "%s" {} \; | awk '{SUM+=$0} END {print SUM/1024/1024}'
    

    Got the correct answer as well, exactly the same as pavium's solution, could be a bit more reliable though.